为了简单起见,我改编了gallery of cartopy's latest release
中的示例,说明了我的问题。fig = plt.figure(figsize=(8, 10))
miller = ccrs.Miller(central_longitude=180)
ax = fig.add_subplot(1, 1, 1, projection=miller)
ax.set_global()
ax.coastlines()
ax.set_yticks(np.arange(-90, 90.5, 30), crs=miller)
lat_formatter = LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)
plt.show()
由于某些原因,y轴标签已更改并且具有奇怪的值。 可能与LatitudeFormatter有关?
重要提示:出于某些与环境相关的原因,我使用的是cartopy 0.18.0b3.dev15 +
答案 0 :(得分:3)
Cartopy完全满足您的要求,即Miller投影中(-90,-60,-30、0、30、60、90)处的标签,即不在纬度。由于您使用的是LatitudeFormatter
,因此会将这些Miller投影点转换为纬度以供显示。
您想要做的是在经纬坐标系中进行标注,因此在创建刻度时,应使用ccrs.PlateCarree()
作为crs
参数,如下所示:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LatitudeFormatter
import numpy as np
fig = plt.figure(figsize=(8, 10))
miller = ccrs.Miller(central_longitude=180)
ax = fig.add_subplot(1, 1, 1, projection=miller)
ax.set_global()
ax.coastlines()
ax.set_yticks(np.arange(-90, 90.5, 30), crs=ccrs.PlateCarree())
lat_formatter = LatitudeFormatter()
ax.yaxis.set_major_formatter(lat_formatter)
plt.show()