matplotlib 无法使用制图在南极立体Map上显示格网标注

nkhmeac6  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(145)

我尝试在Python中使用cartopy绘制极坐标立体图。我能够成功绘制Map,但在显示网格标签时遇到问题。
下面是我的代码:

  1. import cartopy.crs as ccrs
  2. import cartopy.feature as cfeature
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import matplotlib.path as mpath
  6. fig = plt.figure(figsize =(12,8))
  7. ax = plt.axes(projection=ccrs.SouthPolarStereo())
  8. ax.set_extent([-180,180,-90,-30], ccrs.PlateCarree())
  9. ax.add_feature(cfeature.LAND, color='darkgrey')
  10. ax.add_feature(cfeature.OCEAN, color= 'lightblue')
  11. ax.add_feature(cfeature.COASTLINE, linewidth=1.25)
  12. ax.gridlines(ccrs.PlateCarree(), draw_labels=True, linewidth=0.5,
  13. color='grey', xlocs = np.arange(-180,180,30),ylocs = np.arange(-85,-30,20))
  14. theta = np.linspace(0, 2*np.pi, 100)
  15. center, radius = [0.5, 0.5], 0.5
  16. verts = np.vstack([np.sin(theta), np.cos(theta)]).T
  17. circle = mpath.Path(verts * radius + center)
  18. ax.set_boundary(circle, transform = ax.transAxes)
  19. plt.tight_layout()
  20. plt.show()

这将生成一个带有网格线的Map,但未显示标签。如何显示网格线的标签?
谢谢你的帮助!

iqjalb3h

iqjalb3h1#

我不能复制这个。下面的代码片段是一个轻微的修改,切换标签和关闭,但与您的原始代码,它看起来一样的左轴对我来说。

  1. fig, axs = plt.subplots(1,2,
  2. figsize=(8,4), dpi=96, facecolor="w", layout="compressed",
  3. subplot_kw=dict(projection=ccrs.SouthPolarStereo()),
  4. )
  5. for i, draw_labels in enumerate([True, False]):
  6. axs[i].set(title=f"{draw_labels=}")
  7. axs[i].gridlines(
  8. ccrs.PlateCarree(), draw_labels=draw_labels, linewidth=0.5,
  9. color='grey', xlocs = np.arange(-180,180,30),ylocs = np.arange(-85,-30,20),
  10. )
  11. for ax in axs:
  12. ax.set_extent([-180,180,-90,-30], ccrs.PlateCarree())
  13. ax.add_feature(cfeature.LAND, color='darkgrey')
  14. ax.add_feature(cfeature.OCEAN, color= 'lightblue')
  15. ax.add_feature(cfeature.COASTLINE, linewidth=1.25)
  16. theta = np.linspace(0, 2*np.pi, 100)
  17. center, radius = [0.5, 0.5], 0.5
  18. verts = np.vstack([np.sin(theta), np.cos(theta)]).T
  19. circle = mpath.Path(verts * radius + center)
  20. ax.set_boundary(circle, transform = ax.transAxes)

展开查看全部

相关问题