Giter Site home page Giter Site logo

frykit's Introduction

frykit

一个配合 Matplotlib 和 Cartopy 使用的工具箱,主要提供添加刻度和绘制**行政区划等功能。

安装

pip install frykit

依赖仅需 cartopy>=0.20.0

示例

为兰伯特投影的 GeoAxes 添加刻度

import frykit.plot as fplot

crs = ccrs.LambertConformal(central_longitude=105, standard_parallels=(25, 47))
ax = fig.add_subplot(111, projection=crs)

fplt.set_extent_and_ticks(
    ax, extents=[74, 136, 14, 56],
    xticks=np.arange(50, 161, 10),
    yticks=np.arange(0, 71, 10),
    grid=True, lw=0.5, ls='--', color='gray'
)

获取代表**行政区划的多边形对象

import frykit.shp as fshp

country = fshp.get_cnshp(level='国')
provinces = fshp.get_cnshp(level='省')

行政区划的 shapefile 文件来自 ChinaAdminDivisonSHP 项目,坐标已从 GCJ-02 坐标系处理到了 WGS84 坐标系上。

AxesGeoAxes 上直接绘制**省界和九段线

fplt.add_cn_province(ax, lw=0.3)
fplt.add_nine_line(ax, lw=0.5)

添加自备的多边形对象并填色

pc = fplt.add_polygons(
    ax, polygons, ccrs.PlateCarree(), array=data,
    cmap=cmap, norm=norm, ec='k', lw=0.4
)
cbar = fig.colorbar(pc, ax=ax)

用国界裁剪等值线填色图

cf = ax.contourf(
    lon, lat, data, levels, cmap='turbo',
    extend='both', transform=ccrs.PlateCarree()
)
fplt.clip_by_cn_border(cf, fix=True)

添加指北针和比例尺

fplt.add_north_arrow(ax, (0.95, 0.9))
fplt.add_map_scale(ax, (0.1, 0.1), length=1000, ticks=[0, 500, 1000])

定位南海地图

sub = fig.add_axes(ax.get_position(), projection=crs_map)
<plotting on sub>
fplt.locate_sub_axes(ax, sub, shrink=0.4)

效果如下图所示

contourf

fill

nerv_style

示例代码请见 test 目录。

frykit's People

Contributors

zhajiman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.