简体   繁体   English

在 NorthPolarStereo Cartopy 中设置纬度刻度标签的经度

[英]Setting longitude of latitude tick labels in NorthPolarStereo Cartopy

I am making a plot of the Arctic region using code similar to:我正在使用类似于以下的代码制作北极地区的 plot:

from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.ticker as mticker
import cartopy.crs as ccrs

fig, ax = plt.subplots(1,1,figsize=(8,8),  subplot_kw={'projection': ccrs.NorthPolarStereo()})

ax.scatter([x[0] for x in max_coords[:-1]],
           [x[1] for x in max_coords[:-1]],
           color='k',
           s=50,
           marker='x',transform=ccrs.PlateCarree(),zorder=5,
           label='BSH Center\n1980-2020')

ax.set_extent([-2.633e+06, 2.696e+06, -6e+04, 2.9e+06], crs=ccrs.NorthPolarStereo()) 

ax.add_feature(cartopy.feature.LAND, edgecolor='black',zorder=1)

ax.legend(fontsize='x-large')

gl = ax.gridlines(draw_labels=True)

gl.xlocator = mticker.FixedLocator(np.concatenate([np.arange(-180,-89,15),np.arange(90,181,15)]))
gl.xformatter = LONGITUDE_FORMATTER
gl.xlabel_style = {'size': 12, 'color': 'k','rotation':0}

gl.yformatter = LATITUDE_FORMATTER
gl.ylocator = mticker.FixedLocator(np.arange(70,86,5),200)

在此处输入图像描述

As you can see, the ticks denoting the latitude are at a longitude of 135E.如您所见,表示纬度的刻度位于经度 135E。 This means that the 75N tick is over an island and not legible.这意味着 75N 刻度线位于一个岛上并且不清晰。 I would like these ticks to be on the line of 120E, but can't find out how to move them.我希望这些刻度线位于 120E 线上,但不知道如何移动它们。 I thought I could do it with the last two lines of my code above, but they don't seem to make any difference to the plot.我想我可以用上面代码的最后两行来做到这一点,但它们似乎对 plot 没有任何影响。

This needs some hacks on the labels.这需要对标签进行一些修改。 First, you can run this code:首先,您可以运行以下代码:

gl.label_artists

and found that the in line labels are located at 138 degrees longitude.发现in line内标签位于经度 138 度。 With this information, you can change it to other values, and I choose 126 with these lines of code:有了这些信息,您可以将其更改为其他值,我选择 126 与这些代码行:

plt.draw() 
for ea in gl.label_artists:
    if ea[1]==False:
        tx = ea[2]
        xy = tx.get_position()
        #print(xy)
        if xy[0]==138:
            #print("Yes")
            tx.set_position([126, xy[1]])

np-项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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