设置边界后如何添加刻度标签?

问题描述 投票:0回答:1

我尝试使用.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

cartopy
1个回答
0
投票

您的示例中缺少代码,因此我不确定它是否可以解决您的问题,但是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)

Polar plot with labels

© www.soinside.com 2019 - 2024. All rights reserved.