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

clip时,当地图边界范围大于数据范围时会导致裁切后大范围留白,求问怎么解决 #97

Closed
huddao opened this issue Jun 20, 2023 · 4 comments
Assignees

Comments

@huddao
Copy link

huddao commented Jun 20, 2023

裁切前:
image

裁切后会导致大范围留白:
image
image
找了很久都没解决,希望能帮忙看看是哪里的问题。

@Clarmy
Copy link
Member

Clarmy commented Jun 20, 2023

收到,我测试一下

@Clarmy Clarmy self-assigned this Jun 20, 2023
@Clarmy
Copy link
Member

Clarmy commented Jun 20, 2023

@huddao 你试一下这个样例:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

from cnmaps import get_adm_maps, clip_contours_by_map, draw_maps, MapPolygon
from cnmaps.sample import load_temp
from shapely.geometry import Polygon

fig = plt.figure(figsize=(6, 5), dpi=300)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=ccrs.PlateCarree())
lons, lats, data = load_temp()
cs = ax.contourf(lons, lats, data)

boundary = MapPolygon(
    [Polygon([[70, 55], [140, 55], [140, 40], [70, 40], [70, 55]])]
) & get_adm_maps(country="中华人民共和国", only_polygon=True, record="first")

draw_maps(get_adm_maps(country="中华人民共和国"), ax)
clip_contours_by_map(cs, boundary, ax)
ax.set_extent([70, 140, 40, 55], crs=ccrs.PlateCarree())
fig.savefig("./test.png", bbox_inches="tight")

test

@huddao
Copy link
Author

huddao commented Jun 20, 2023

感谢,完美解决

@huddao
Copy link
Author

huddao commented Jun 20, 2023

记录:可以通过ax的get_extent方法获取到边界,再通过boundary = MapPolygon( [Polygon([[70, 55], [140, 55], [140, 40], [70, 40], [70, 55]])] ) & get_adm_maps(country="中华人民共和国", only_polygon=True, record="first")的方法构建新的boundary用于裁切

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

2 participants