Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

避免裁剪出界问题 #112

Open
ZhaJiMan opened this issue Feb 16, 2024 · 0 comments
Open

避免裁剪出界问题 #112

ZhaJiMan opened this issue Feb 16, 2024 · 0 comments

Comments

@ZhaJiMan
Copy link
Contributor

对于裁剪后裁剪内容超出 Axes的情况(#97#99#111
添加 contours.set_clip_box(ax.bbox) 即可解决。以文档中的 剪切地图 为例

example

测试代码为

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cnmaps import get_adm_maps, clip_contours_by_map, draw_map
from cnmaps.sample import load_dem

lons, lats, data = load_dem()

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
ax.set_extent([70, 140, 40, 55], crs=ccrs.PlateCarree())
map_polygon = get_adm_maps(country='中华人民共和国', record='first', only_polygon=True)

cs = ax.contourf(lons, lats, data,
                cmap=plt.cm.terrain,
                levels=np.linspace(-2800, data.max(), 10),
                transform=ccrs.PlateCarree())

clip_contours_by_map(cs, map_polygon)
draw_map(map_polygon, color='k', linewidth=1)

plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant