CATTOPY无法显示Eckertiii投影的纬度标签

发布于 2025-02-11 21:36:51 字数 1642 浏览 0 评论 0原文

Cartopy并未在简单的图中显示纬度标签。 可以设置什么以显示纬度标签? 这些代码将创建图形,但未显示LAT标签。 如果将投影更改为Platecarree,则没有问题可以显示标签。

Python代码是:

# Setup a global EckertIII map with faint coastlines.
fig = plt.figure(figsize=(16, 8))

ax = fig.add_subplot(2,2,1, projection=ccrs.EckertIII())
# ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
x = np.arange(-90, 90)
y = x.copy()
x2, y2 = np.meshgrid(x, y)
z = x2*y2
filled_c = ax.contourf(x2, y2, z, transform=ccrs.PlateCarree())
line_c = ax.contour(x2, y2, z, levels=filled_c.levels,
                    colors=['black'],
                    transform=ccrs.PlateCarree())
plt.colorbar(filled_c, orientation='vertical', ax=ax)
ax.set_global()
ax.coastlines('110m', alpha=0.1)
# Use the line contours to place contour labels.
ax.clabel(
    line_c,  # Typically best results when labelling line contours.
    colors=['black'],
    manual=False,  # Automatic placement vs manual placement.
    inline=True,  # Cut the line where the label will be placed.
    fmt=' {:.0f} '.format,  # Labes as integers, with some extra space.
)
# # s0
# ax.gridlines(color='k', linestyle='--', draw_labels=True)

# # s1
gl = ax.gridlines(
    xlocs=[-180, -120, -60, 0, 60, 120, 180],
    ylocs=[-90, -60, -30, 0, 30, 60, 90],
    draw_labels=True, x_inline=False, y_inline=False,
    lw=0.5, linestyle='--', color='gray'
)
# gl.top_labels = False
# gl.right_labels = True
gl.rotate_labels = False

Cartopy is not showing latitude labels in a simple plot.
What can be set to show the latitude labels?
The codes will create the figure, but the lat labels not shown.
If change the projection to PlateCarree, then there is no problem to show labels.

enter image description here

The python code is:

# Setup a global EckertIII map with faint coastlines.
fig = plt.figure(figsize=(16, 8))

ax = fig.add_subplot(2,2,1, projection=ccrs.EckertIII())
# ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
x = np.arange(-90, 90)
y = x.copy()
x2, y2 = np.meshgrid(x, y)
z = x2*y2
filled_c = ax.contourf(x2, y2, z, transform=ccrs.PlateCarree())
line_c = ax.contour(x2, y2, z, levels=filled_c.levels,
                    colors=['black'],
                    transform=ccrs.PlateCarree())
plt.colorbar(filled_c, orientation='vertical', ax=ax)
ax.set_global()
ax.coastlines('110m', alpha=0.1)
# Use the line contours to place contour labels.
ax.clabel(
    line_c,  # Typically best results when labelling line contours.
    colors=['black'],
    manual=False,  # Automatic placement vs manual placement.
    inline=True,  # Cut the line where the label will be placed.
    fmt=' {:.0f} '.format,  # Labes as integers, with some extra space.
)
# # s0
# ax.gridlines(color='k', linestyle='--', draw_labels=True)

# # s1
gl = ax.gridlines(
    xlocs=[-180, -120, -60, 0, 60, 120, 180],
    ylocs=[-90, -60, -30, 0, 30, 60, 90],
    draw_labels=True, x_inline=False, y_inline=False,
    lw=0.5, linestyle='--', color='gray'
)
# gl.top_labels = False
# gl.right_labels = True
gl.rotate_labels = False

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-02-18 21:36:51

我自己解决了该数字两次的网格电话,我自己解决了问题。
第一次运行设置为旋转标签TRUE,然后将第二次运行设置为此False。
然后,将为他们绘制网格线。

 # 1st to draw the rotate labels
    gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=True)
  
    # 2nd to draw the non-rotate labels
    gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=True)
  
    gl.rotate_labels = False

I solved the problem myself, by running gridlines for the figure twice.
First run is set rotate labels True, and 2nd run is set this False.
Then the gridlines will be drawn for them.

 # 1st to draw the rotate labels
    gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=True)
  
    # 2nd to draw the non-rotate labels
    gl = ax.gridlines(color='k', linestyle='--', lw=0.5, draw_labels=True)
  
    gl.rotate_labels = False
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文