在x轴上旋转底图Meridian标签

时间:2015-07-16 17:52:03

标签: python matplotlib label axis-labels matplotlib-basemap

是否可以旋转子午线标签以使它们不再重叠?有关下面的示例,请参见图像。我不想减少子午线的数量。

我试过了:

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

虽然这在底图中没有做任何事情。

enter image description here

2 个答案:

答案 0 :(得分:5)

子午线标签不是xaxis标签。您仍然可以操纵他们的文本对象:

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()

enter image description here

答案 1 :(得分:1)

只需给出一个角度作为mapproj.drawmeridians()的“rotation”参数。

int main(void) {
        int x = 0x7fffffff;
        int ret = sign_bit_check(x);
        if(ret) {
                printf("Negative\n");
        }
        else {
                printf("positive \n");
        }
        return 0;
}

enter image description here

就是这样! 干杯!