2017-10-11 134 views
1

有没有办法在地图上旋转纬度刻度标签?我知道在QGIS等GIS程序中这是一个非常简单和常用的选项,但是在使用cartopy时我找不到关于这个主题的任何内容。旋转纬度(y)刻度标签 - cartopy

下面有一个简单的例子(我绘制我自己shape文件,我这里不表达):

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°,以便它们变得垂直?

+2

您可以编辑您的问题包括[MCVE(https://stackoverflow.com/help/mcve)?对于你的问题,就像代码一样,它以你拥有它们的方式创建一个经度坐标的例子,以及你所说的“地图框架”的含义,以及你想要转换这些对象的细节。 –

+0

@JeremyMcGibbon感谢您的收入。对像我这样的初学者非常有帮助。我提出的例子并不是最好的,我从我的代码改编而来,但它可能会澄清我想说的话。 – hperes

回答

0

由于cartopy坐标轴只是一个特殊的matplotlib坐标轴,很多可以对matplotlib坐标图执行的操作,您也可以对cartopy坐标图进行操作。

对于旋转滴答标签,有一个example in the matplotlib gallery

所以,转动你的Ÿ刻度标记你只需要添加以下代码:

plt.yticks(rotation='vertical') 

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

[x_min, x_max, y_min, y_max] 

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

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

谢谢@ldreyer!我没有这样想,cartopy依赖于matplotlib的参数。顺便说一句,set_extent是正确的,我切换set_xticks和set_yticks行中的坐标。我在问题中纠正了它。再次感谢! – hperes