### Install Frykit Source: https://github.com/zhajiman/frykit/blob/main/README.md Installs the frykit package, with an option to include map data for full functionality. It also shows how to update the package. ```bash pip install frykit # 需要地图数据 pip install frykit[data] # 更新 pip install -U frykit ``` -------------------------------- ### Plot World Base Map Source: https://github.com/zhajiman/frykit/blob/main/README.md Provides examples for plotting world base maps using `frykit.plot`. It shows how to add country borders and visualize land and ocean areas with specified fill colors. ```Python # 画所有国家 fplt.add_countries(ax) # 画海陆 fplt.add_land(ax, fc='floralwhite') fplt.add_ocean(ax, fc='dodgerblue') ``` -------------------------------- ### Read Chinese Administrative Boundaries Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates how to read various Chinese administrative boundaries using the `frykit.shp` module. It covers reading national borders, coastlines, provinces, cities, and districts, with examples of filtering by name or administrative code. ```Python import frykit.shp as fshp 国界 = fshp.get_cn_border() 九段线 = fshp.get_cn_line() 所有省 = fshp.get_cn_province() 安徽省 = fshp.get_cn_province('安徽省') 安徽省, 江苏省 = fshp.get_cn_province(['安徽省', '江苏省']) 所有市 = fshp.get_cn_city() 合肥市 = fshp.get_cn_city('合肥市') 合肥市, 六安市 = fshp.get_cn_city(['合肥市', '六安市']) 安徽省的所有市 = fshp.get_cn_city(province='安徽省') 安徽省和江苏省的所有市 = fshp.get_cn_city(province=['安徽省', '江苏省']) 所有区县 = fshp.get_cn_district() 蜀山区 = fshp.get_cn_district('蜀山区') 蜀山区, 包河区 = fshp.get_cn_district(['蜀山区', '包河区']) 合肥市的所有区县 = fshp.get_cn_district(city='合肥市') 安徽省的所有区县 = fshp.get_cn_district(province='安徽省') # 通过行政区划代码查询 北京市 = fshp.get_cn_province(110000) 京津冀 = fshp.get_cn_province([110000, 120000, 130000]) ``` -------------------------------- ### Plot Chinese Administrative Boundaries Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates plotting Chinese administrative boundaries using the `frykit.plot` module. It includes functions for plotting national borders, coastlines, provinces, cities, and districts, along with functions for labeling them. The example shows how to color-code specific regions and use a predefined Cartopy projection. ```Python import matplotlib.pyplot as plt import frykit.plot as fplt plt.figure(figsize=(8, 8)) ax = plt.axes(projection=fplt.PLATE_CARREE) fplt.add_cn_province(ax) fplt.add_cn_province(ax, ['北京市', '天津市', '河北省'], fc='dodgerblue') fplt.add_cn_line(ax) fplt.label_cn_province(ax) plt.show() # 画出所有省份,同时用颜色区分京津冀地区 # 其中 fplt.PLATE_CARREE 只是一个 ccrs.PlateCarree() 实例,这样就无需在脚本开头导入 cartopy.crs。 ax = plt.axes(projection=fplt.PLATE_CARREE) fplt.add_cn_district(ax, province='北京市', fc=plt.cm.Pastel1.colors) fplt.label_cn_district(ax, province='北京市') plt.show() # 画出北京所有区 ``` -------------------------------- ### Add Mini Map Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates how to add a small overview map (mini map) to a larger geospatial plot using Frykit's `add_mini_axes` function. This function automatically positions the mini map in a corner and uses the same projection as the main map, simplifying the setup. ```Python mini_ax = fplt.add_mini_axes(ax) mini_ax.set_extent((105, 120, 2, 25), crs=fplt.PLATE_CARREE) fplt.add_cn_province(mini_ax) fplt.add_cn_line(mini_ax) ``` -------------------------------- ### Switch Data Source in Frykit Source: https://github.com/zhajiman/frykit/blob/main/README.md Explains how to switch between different administrative boundary data sources (Gaode Maps and Tianditu) in Frykit. It shows methods using function parameters, global configuration, and context managers. ```Python # 通过函数参数指定 amap_cities = fshp.get_cn_city(data_source='amap') tianditu_cities = fshp.get_cn_city(data_source='tianditu') # 在脚本开头设置全局数据源 import frykit frykit.set_option({'data_source': 'tianditu'}) # 用上下文管理器临时设置数据源 with frykit.option_context({'data_source': 'tianditu'}): cities = fshp.get_cn_city() some_function(cities) # 0.7.5 开始可以直接修改 frykit.config.data_source 属性来设置数据源 # frykit.config.data_source = 'tianditu' ``` -------------------------------- ### Environment Versions Source: https://github.com/zhajiman/frykit/blob/main/README.md Lists the specific versions of Python and key libraries (Cartopy, Frykit) used in the performance tests. These versions are crucial for reproducibility and understanding the test environment. ```Python # Environment Versions python==3.11.9 cartopy==0.24.0 frykit==0.7.2.post1 ``` -------------------------------- ### Clip Artist with Multiple Provinces Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates clipping a plot artist using a list of specific Chinese provinces. The `clip_by_cn_province` function allows for targeted clipping by providing a list of province names. ```Python fplt.clip_by_cn_province(artist, ['北京市', '天津市', '河北省']) ``` -------------------------------- ### Create Qualitative Colorbar Source: https://github.com/zhajiman/frykit/blob/main/README.md Provides a method to create a qualitative colorbar where each discrete color corresponds to a specific tick label. This is useful for categorical data and is achieved using Frykit's `make_qualitative_palette` and `plot_colormap` functions. ```Python colors = [ 'orangered', 'orange', 'yellow', 'limegreen', 'royalblue', 'darkviolet' ] cmap, norm, ticks = fplt.make_qualitative_palette(colors) cbar = fplt.plot_colormap(cmap, norm) cbar.set_ticks(ticks) cbar.set_ticklabels(colors) ``` -------------------------------- ### Create Centered Boundary Colorbar Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates how to create a colorbar with a centered zero value, where the color scale is symmetric around zero (e.g., blue for negative, white for zero, orange/red for positive). This uses Frykit's `CenteredBoundaryNorm` and a specified colormap. ```Python import cmaps boundaries = [-10, -5, -2, -1, 1, 2, 5, 10, 20, 50, 100] norm = fplt.CenteredBoundaryNorm(boundaries) cbar = fplt.plot_colormap(cmaps.BlueWhiteOrangeRed, norm) cbar.set_ticks(boundaries) ``` -------------------------------- ### Clip Artist with Custom Polygon Source: https://github.com/zhajiman/frykit/blob/main/README.md Illustrates how to clip a plot artist using a custom polygon formed by combining multiple geographic boundaries (e.g., a province and cities). This involves using Shapely for geometric operations like union and Frykit's `clip_by_polygon` function. ```Python import shapely 北京市 = fshp.get_cn_province('北京市') 保定市 = fshp.get_cn_city('保定市') 张家口市 = fshp.get_cn_city('张家口市') polygon = shapely.union_all([北京市, 保定市, 张家口市]) fplt.clip_by_polygon(artist, polygon) ``` -------------------------------- ### Set Map Extent and Ticks with Frykit Source: https://github.com/zhajiman/frykit/blob/main/README.md Simplifies the process of setting map extents and ticks for Cartopy GeoAxes. The `set_map_ticks` function automates the creation of longitude and latitude ticks with specified intervals and formatting, including directional symbols. ```Python import numpy as np import cartopy.crs as ccrs from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter crs = ccrs.PlateCarree() ax.set_extent((70, 140, 0, 60), crs=crs) ax.set_xticks(np.arange(70, 141, 10), crs=crs) ax.set_yticks(np.arange(0, 61, 10), crs=crs) ax.xaxis.set_major_formatter(LongitudeFormatter()) ax.yaxis.set_major_formatter(LatitudeFormatter()) ``` ```Python fplt.set_map_ticks(ax, (70, 140, 0, 60), dx=10, dy=10) ``` -------------------------------- ### Draw Geometries with Frykit Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates how to draw various geographic shapes like country borders, circles, shapefiles, and GeoJSON data using Frykit's `add_geometries` function. This function is similar to Cartopy's `GeoAxes.add_geometries` but works with standard Matplotlib Axes and offers optimizations for projection and filling. ```Python fplt.add_geometries(ax, fshp.get_cn_border()) ``` ```Python import shapely circle = shapely.Point(0, 0).buffer(10) fplt.add_geometries(ax, circle) ``` ```Python from cartopy.io.shapereader import Reader reader = Reader('2023年_CTAmap_1.12版/2023年县级/2023年县级.shp') geometries = list(reader.geometries()) reader.close() fplt.add_geometries(ax, geometries, fc='none', ec='k', lw=0.25) ``` ```Python import json import shapely.geometry as sgeom with open('天地图_行政区划可视化/中国_省.geojson') as f: geometries = [ sgeom.shape(feature["geometry"]) for feature in json.load(f)["features"] ] fplt.add_geometries(ax, geometries, fc='none', ec='k', lw=0.25) ``` -------------------------------- ### Add GMT Style Frame Source: https://github.com/zhajiman/frykit/blob/main/README.md Shows how to add a GMT-style frame (grid lines and labels) to a map using Frykit's `add_frame` function. This function is primarily for Plate Carree or Mercator projections and can also be applied to other artists like scale bars. ```Python fplt.add_frame(ax) ``` ```Python fplt.add_frame(scale_bar) ``` -------------------------------- ### Clip Artist with Country Border Source: https://github.com/zhajiman/frykit/blob/main/README.md Shows how to clip a Matplotlib artist, such as a contour plot, using the country border. This is achieved using Frykit's `clip_by_cn_border` function, which visually removes data outside the specified geographic boundary. ```Python import matplotlib.pyplot as plt import frykit.plot as fplt ax = plt.axes(projection=fplt.PLATE_CARREE) fplt.add_cn_province(ax) fplt.add_cn_line(ax) data = fplt.load_test_data() cf = ax.contourf( data.lon, data.lat, data.t2m, levels=20, cmap='rainbow', transform=fplt.PLATE_CARREE, ) fplt.clip_by_cn_border(cf) plt.show() ``` -------------------------------- ### Create Data Mask with Polygon Source: https://github.com/zhajiman/frykit/blob/main/README.md Explains how to create a data mask based on a geographic polygon using Frykit's `polygon_mask` or `polygon_mask2` functions. This mask can then be used to set data points outside the polygon to NaN (Not a Number) during data processing. ```Python border = fshp.get_cn_border() mask = fshp.polygon_mask(border, lon2d, lat2d) data[~mask] = np.nan ax.contourf(lon2d, lat2d, data) ``` ```Python mask = fplt.polygon_mask2(border, lon1d, lat1d) data[~mask] = np.nan ``` -------------------------------- ### Add Scale Bar Source: https://github.com/zhajiman/frykit/blob/main/README.md Illustrates adding a scale bar to a map using Frykit's `add_scale_bar` function. The scale bar's length is determined by the geographic distance corresponding to a unit length at the map's center. It can be further customized using standard Matplotlib methods. ```Python scale_bar = fplt.add_scale_bar(ax, 0.36, 0.8, length=1000) scale_bar.set_xticks([0, 500, 1000]) ``` -------------------------------- ### Add Wind Vector Legend Source: https://github.com/zhajiman/frykit/blob/main/README.md Demonstrates how to add a wind vector legend to a plot using Frykit's `add_quiver_legend` function. This function places a legend indicating wind speed and direction, typically in the lower right corner of the plot. ```Python Q = ax.quiver(x, y, u, v, transform=fplt.PLATE_CARREE) fplt.add_quiver_legend(Q, U=10, width=0.15, height=0.12) ``` -------------------------------- ### Add North Arrow Source: https://github.com/zhajiman/frykit/blob/main/README.md Shows how to add a north arrow (compass rose) to a geospatial plot using Frykit's `add_compass` function. The position is specified using Axes coordinates, and the arrow automatically points north or can be manually oriented with the `angle` parameter. ```Python fplt.add_compass(ax, 0.95, 0.8, size=15) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.