【问题标题】:How to add the tick labels after set the boundary?设置边界后如何添加刻度标签?
【发布时间】:2020-05-29 10:28:14
【问题描述】:

我尝试使用.set_boundary()后添加刻度标签,但失败了。如何实现?

ax1.set_extent([-180, 180, -90, -60], ccrs.PlateCarree())
ax1.add_feature(cfeature.LAND)
ax1.add_feature(cfeature.OCEAN)
ax1.gridlines()

ax2.gridlines()
ax2.add_feature(cfeature.LAND)
ax2.add_feature(cfeature.OCEAN)
theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)
ax2.set_boundary(circle, transform=ax2.transAxes)

ax1.gridlines(draw_labels=True)
ax2.gridlines(draw_labels=True)

enter image description here

【问题讨论】:

  • 感谢您的帖子。当你在 stackoverflow 上提问时,你需要做两件你没有做过的事情。首先,您需要为您的问题提供更多上下文,您使用什么语言进行编码,您使用什么库,版本等。您提供的上下文越多,可以帮助您的人就越多。其次,您还需要为您的问题添加标签,标签有助于对您的帖子进行分类,以便具有正确知识的用户可以找到您的问题和帮助。调整您的问题,我相信有人会提供帮助。

标签: cartopy


【解决方案1】:

您的示例中缺少代码,因此我不能确定它是否能解决您的问题,但 Cartopy 仅允许从 0.18 版(whats newPR)开始对所有投影进行经度和纬度标记。在此之前,只允许 PlateCarree 和 Mercator,任何其他投影都会因错误而失败:

TypeError: Cannot label gridlines on a SouthPolarStereo plot. Only PlateCarree and Mercator plots are currently supported.

使用 v0.18 的代码(我从上面链接的 PR 中获得)使 lonlat 标签很好:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

projection = ccrs.SouthPolarStereo()
extent = [-180, 180, -90, -60]

fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, projection=projection)
ax.set_extent(extent, crs=ccrs.PlateCarree())
ax.coastlines(resolution='50m', color='k')
ax.gridlines(color='lightgrey', linestyle='-', draw_labels=True)

【讨论】:

    猜你喜欢
    • 2021-12-21
    • 2021-06-14
    • 1970-01-01
    • 2016-05-28
    • 2014-08-13
    • 1970-01-01
    • 2021-03-10
    • 2019-05-21
    • 1970-01-01
    相关资源
    最近更新 更多