繁体   English   中英

旋转纬度 (y) 刻度标签 - 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM