set_clip_path使绘图在轴的外侧

问题描述

我想在一个国家形状内绘制轮廓线。所以我使用以下代码

def get_geometries(*readers):
    geoms = []
    for reader in readers:
        for record in reader.records():
            geoms += [record.geometry]
    return geoms

fig = plt.figure(figsize=(12,6))

proj = ccrs.PlateCarree()
ax = plt.axes(projection=proj)
ax.set_extent([100,140,15,60],crs=proj)

reader = Reader('*.shp')

geoms = get_geometries(reader)
ax.add_geometries(geoms,proj,edgecolor='black',facecolor='none',alpha=0.5)

contour = ax.contourf(gx,gy,grid_data,cmap=cmap,levels=levels,extend='both')
# mask the contour plot outside the shape file
path = Path.make_compound_path(*geos_to_path(geoms))
patch = mpatches.PathPatch(path,transform=ax.transData)
for col in contour.collections:
    col.set_clip_path(patch)

但是事实证明,如果我使用set_clip_path函数,则ax.set_extent将无效。如果我注释了代码的最后四行,则ax.set_extent很有用。

我想cartopy或Matplotlib有一些变化。因为这段代码以前运行良好。

谢谢

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...