简体   繁体   English

在x轴上旋转底图子午线标签

[英]Rotating Basemap Meridian labels on x-axis

Is it possible to rotate the meridian labels so that they are no longer overlapping? 是否可以旋转子午线标签,使其不再重叠? See the image for an example below. 请参见下面的示例图像。 I don't want to reduce the number of meridian lines. 我不想减少子午线的数量。

I've tried: 我试过了:

ax = plt.gca()
ax.set_xticklabels( meridians, rotation=45 )

This doesn't do anything in Basemap though. 但是,这在底图中什么也没做。

在此处输入图片说明

The meridian labels aren't xaxis labels. 经络标签不是xaxis标签。 You can still manipulate their text objects: 您仍然可以操纵他们的文本对象:

from mpl_toolkits.basemap import Basemap, cm
import numpy as np
import matplotlib.pyplot as plt

# create figure and axes instances
fig = plt.figure(figsize=(8,8))
ax = fig.add_axes([0.1,0.1,0.8,0.8])
# create polar stereographic Basemap instance.
m = Basemap(projection='stere',lon_0=0,lat_0=30.,lat_ts=45.,\
            width=10000000, height=4000000,
            rsphere=6371200.,resolution='l',area_thresh=10000)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
# draw parallels.
parallels = np.arange(0.,90,5.)
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
# draw meridians
merid_values = np.arange(0.,360.,10.)
meridians = m.drawmeridians(merid_values,labels=[0,0,0,1],fontsize=10)
for m in meridians:
    try:
        meridians[m][1][0].set_rotation(45)
    except:
        pass
plt.show()

在此处输入图片说明

Just give an angle as the "rotation" argument of the mapproj.drawmeridians(). 只需指定一个角度作为mapproj.drawmeridians()的“旋转”参数即可。

import mpl_toolkits.basemap as bm

mapproj = bm.Basemap(ax=ax1,projection='cyl',llcrnrlat=lat_mn, \
                     llcrnrlon= lon_mn,urcrnrlat= lat_mx, urcrnrlon=lon_mx)
mapproj.drawmeridians(lonlines, labels=[0,0,1,0],rotation=45)

在此处输入图片说明

That's it! 而已! Cheers! 干杯!

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

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