gpt4 book ai didi

python - 如何纠正反向 basemap 图中错误的刻度标签位置

转载 作者:行者123 更新时间:2023-12-01 07:52:36 25 4
gpt4 key购买 nike

我正在尝试使用 basemap 绘制天体区域。当我反转 x 轴 (RA) 时,刻度标 checkout 现在错误的一侧。怎么解决?

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

enter image description here

最佳答案

要正确绘制平行线的标签,需要使用以下代码行来代替相关代码:

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

输出将是:

enter image description here

完整代码:

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 操作。

关于python - 如何纠正反向 basemap 图中错误的刻度标签位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56129258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com