matplotlib - 声明后如何关闭cartopy中的网格线?
问题描述
我想添加一个选项来使用函数打开/关闭网格线。但是一旦打开网格线就无法禁用它,我尝试将 xlines 和 ylines 设置为 False 但没有按预期的方式工作,有没有其他选择?我正在使用 matplotlib.figure.figure 而不是 plt。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
ax.gridlines()
有没有办法从轴上删除网格线?
解决方案
要从轴上的绘图中删除网格线,您可以执行以下操作:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
# .gridlines() creates `gridliner` object
# grab it and assign it as `gl`
gl = ax.gridlines()
# manipulate `gridliner` object
gl.xlabels_top = False
gl.ylabels_left = False
gl.xlines = False
gl.ylines = False
plt.show()
推荐阅读
- wordpress - 在 Wordpress 网站上获取 Map API 密钥错误
- javascript - 在 javascript 中对据说未定义的变量获取未捕获的引用错误。我不知道为什么
- r - 将每个组的 SD 添加到变量中
- java - Java Generic 如何转换为子类型以调用泛型方法
- sql - 在 SQL Server 中查询 Datediff 以输出 HH:MM
- python-3.x - 为什么 Python 3 Windows AMD64/EM64T/x64 安装程序是“.amd64”文件?
- javascript - 使用Angular4直接更新到innerHTML时如何提高性能
- java - 检查对象以确保它不为空
- google-apps-script - Google 表格中的自动增量数据验证
- docker - 使用用户名/密码使用 nfs 挂载网络共享