有没有办法旋转 cartopy map 中的纬度刻度标签?我知道这是 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 图执行。
对于旋转刻度标签,有 example in the matplotlib gallery .
因此,要旋转 y 刻度标签,您只需将以下内容添加到代码中:
plt.yticks(rotation='vertical')
我还注意到您的 map 范围顺序错误。顺序应该是
[x_min, x_max, y_min, y_max]
所以你的代码应该是这样的:
mapp.set_extent([-24.35, -23.36, -45.6, -44.2])
关于python - 旋转纬度 (y) 刻度标签 - cartopy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46678883/