![](/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.