![](/img/trans.png)
[英]Setting longitude of latitude tick labels in NorthPolarStereo Cartopy
[英]Weird setting of latitude labels in cartopy Miller projection
只是为了让事情变得简单,我复制了我的问题,从cartopy 最新版本的画廊中改编了一个例子
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+
Cartopy 提供的正是您所要求的,即米勒投影中 (-90, -60, -30, 0, 30, 60, 90) 处的标签,即不是纬度。 因为您使用的是LatitudeFormatter
,所以它将这些米勒投影点转换为纬度以供您显示。
看起来您想要做的是 label 在纬度/经度坐标系中,因此您应该在创建刻度时使用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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.