![](/img/trans.png)
[英]Setting longitude of latitude tick labels in NorthPolarStereo Cartopy
[英]Rotate latitude (y) tick labels - cartopy
有沒有辦法在 cartopy 地圖中旋轉緯度刻度標簽? 我知道在 QGIS 等 GIS 程序中這是一個非常簡單且常用的選項,但是在使用 cartopy 時我找不到有關該主題的任何內容。
下面是一個簡單的例子(我繪制了我自己的 shapefile,我沒有在這里表達):
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
mapp = plt.subplot(111, projection=ccrs.PlateCarree())
mapp.set_extent([-44.2, -45.6, -23.36, -24.35])
mapp.set_yticks([-23.5,-24], crs=ccrs.PlateCarree())
mapp.set_xticks([-44.5,-45.5], crs=ccrs.PlateCarree())
lon_formatter = LongitudeFormatter(number_format='.1f')
lat_formatter = LatitudeFormatter(number_format='.1f')
mapp.xaxis.set_major_formatter(lon_formatter)
mapp.yaxis.set_major_formatter(lat_formatter)
plt.show()
它不是最好的 MCVE,但無論如何,它會水平顯示緯度刻度標簽——這是一個標准。 我的問題是:有沒有辦法將緯度刻度標簽(或 y 刻度標簽)旋轉 90°,使它們垂直?
由於 cartopy 軸只是一個特殊的 matplotlib 軸,因此您可以對 matplotlib 圖執行很多操作,也可以對 cartopy 圖執行很多操作。
對於旋轉刻度標簽, matplotlib 庫中有一個示例。
因此,要旋轉您的 y 刻度標簽,您只需將以下內容添加到您的代碼中:
plt.yticks(rotation='vertical')
我還注意到您的地圖范圍的順序錯誤。 順序應該是
[x_min, x_max, y_min, y_max]
所以你的代碼應該是這樣的:
mapp.set_extent([-24.35, -23.36, -45.6, -44.2])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.