【问题标题】:Rotate latitude (y) tick labels - cartopy旋转纬度 (y) 刻度标签 - cartopy
【发布时间】:2017-10-11 02:35:45
【问题描述】:

有没有办法在地图上旋转纬度刻度标签?我知道在 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°,使它们垂直?

【问题讨论】:

  • 您能否编辑您的问题以包含MCVE?对于您的问题,这类似于代码,它以您拥有它们的方式创建一个示例经度坐标,以及您所说的“地图框”,以及您想要将这些对象转换为的详细信息。
  • @JeremyMcGibbon 感谢您的收入。对我这样的初学者很有帮助。我举的例子不是最好的,我改编自我的代码,但它可能会澄清我想说的。

标签: python matplotlib cartopy


【解决方案1】:

由于cartopy轴只是一个特殊的matplotlib轴,你可以对matplotlib图做很多事情,你也可以对cartopy plot做。

对于旋转刻度标签,有一个example in the matplotlib gallery

因此,要旋转 y 刻度标签,您只需在代码中添加以下内容:

plt.yticks(rotation='vertical')

我还注意到您的地图范围的顺序错误。顺序应该是

[x_min, x_max, y_min, y_max]

所以你的代码应该是这样的:

mapp.set_extent([-24.35, -23.36, -45.6, -44.2])

【讨论】:

  • 谢谢@ldreyer!我没想到,c​​artopy 依赖于 matplotlib 的参数。顺便说一句,set_extent 是对的,我切换了 set_xticks 和 set_yticks 行中的坐标。我在问题中纠正了它。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-04
  • 2015-10-29
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多