我正在尝试使用底图绘制一个天体区域。当我反转x轴(RA)时,刻度标签出现在错误的一侧。怎么解决?
from mpl_toolkits.basemap import Basemap
import pylab as pl
width = 250000
m = Basemap(width=width, height=width, projection='aeqd',
lat_0=57.1, lon_0=35.2)
m.drawmeridians(np.arange(32,37.8,1),labels=[True]*5)
m.drawparallels(np.arange(56,58,0.5),labels=[True]*5)
pl.gca().invert_xaxis()
pl.show()
答案 0 :(得分:1)
要正确绘制平行线的标签,需要用以下几行代码代替相关的代码:
m.drawparallels(np.arange(56,58,0.5), ha= 'right', labels=[0, 1, 0, 0]) # for labels on left side
m.drawparallels(np.arange(56,58,0.5), ha= 'left', labels=[1, 0, 0, 0]) # for labels on right side
输出将是:
完整代码:
from mpl_toolkits.basemap import Basemap
import numpy as np
from matplotlib import pyplot as plt
width = 250000
m = Basemap(width=width, height=width, projection='aeqd',
lat_0=57.1, lon_0=35.2)
m.drawmeridians(np.arange(32,37.8,1), labels=[0, 0, 1, 1])
m.drawparallels(np.arange(56,58,0.5), ha= 'right', labels=[0, 1, 0, 0]) # for labels on left side
m.drawparallels(np.arange(56,58,0.5), ha= 'left', labels=[1, 0, 0, 0]) # for labels on right side
plt.gca().invert_xaxis()
plt.show()
编辑
要启用通过Google Colab运行代码,请遵循以下Gist