https://i.imgur.com/dRH1ZMT.png
我有这个极坐标图,我想移动纬度标签,使其位于线条下方。
我在网上能找到的任何东西都行不通,有人有办法吗?
这是我的代码:
ax = pyplot.subplot(polar=True)
ax.plot(data blah blah blah)
#rotate map
ax.set_theta_offset((3*math.pi)/2)
#set labels
ax.axes.get_xaxis().set_ticks([0, (math.pi)/2, (math.pi), (3*math.pi)/2])
ax.axes.get_yaxis().set_ticks([-50, -60, -70, -80])
ax.set_xticklabels(["0 MLT", "6", "12", "18"])
#change colors of axis to gray
ax.xaxis.grid(True,color='dimgray',linestyle='-', linewidth = 1)
ax.yaxis.grid(True,color='dimgray',linestyle='-', linewidth = 1)
#margins to zero
pyplot.margins(0)
答案 0 :(得分:0)
official reference中有一个示例,但是您的代码显示得不好。我会建议另一种方式。
import matplotlib.pyplot as plt
import math
ax = plt.subplot(polar=True)
size = 100
x = np.linspace(0, 2 * np.pi, size)
y = np.sin(6*x) + np.random.normal(0, 0.08, (size))
ax.plot(x,y)
#rotate map
ax.set_theta_offset((3*math.pi)/2)
ax.set_thetalim([np.pi, 0])
# angle is degree measure
ax.set_thetagrids([0.0, 90.0, 180.0, 270.0, 360.0],
labels=["0 MLT", "6", "12", "18"], fontsize=12)
ax.set_rlim([-3.0, 3.0])
# angle is degree measure
ax.set_rgrids(np.arange(-3, 3.01, 1), labels=[-50, -60, -70, -80], fontsize=12, angle=180)
#change colors of axis to gray
ax.xaxis.grid(True,color='dimgray',linestyle='-', linewidth = 1)
ax.yaxis.grid(True,color='dimgray',linestyle='-', linewidth = 1)
#margins to zero
plt.margins(0)
答案 1 :(得分:0)
我能够通过在ax.set_yticklabels中添加horizontal_alignment来移动刻度线标签。
我上面发布的代码示例:
ax.set_yticklabels(["-50", "-60", "-70", "-80"], horizontalalignment = "left", verticalalignment = "top")