【发布时间】:2019-11-18 14:18:18
【问题描述】:
我正在尝试重现此图表:
但我在创建带有条形的水平线时遇到了麻烦。我试过annotate 和hlines,但它们并没有达到我想要的效果。
将 matplotlib.pyplot 导入为 plt
plt.grid(which = 'both')
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
plt.xlim(-0.5,8)
plt.ylim(-0.5,10)
plt.xlabel('Redshift, z', fontsize = 16)
plt.hlines(8, 0, .3)
plt.annotate(r'H$\alpha$', fontsize = 16, xy = (0,8), xycoords='data', xytext=(0,8), textcoords='data',
arrowprops=dict(arrowstyle='<|-|>', connectionstyle='arc3', color = 'k', lw=2))
fig = plt.gcf()
width, height = 15,35 # inches
fig.set_size_inches(width, height, forward = True)
plt.show()
制作这样的条的最佳方法是什么?
【问题讨论】:
标签: matplotlib annotate horizontal-line