我想用matplotlib的.vline命令来标记我的垂直线,但是由于某些原因,label参数在最终的绘图上没有任何作用/显示任何东西。有谁知道如何让标签显示出来吗?
plt.vlines(x=pah, ymin=0, ymax=0.6, colors='0.75', linestyles='dashed', label='PAHs')除了标签之外,一切都可以正常工作。
非常感谢,
我
发布于 2014-11-27 01:04:48
label关键字将显示在图例中。您需要显式创建legend才能在绘图中查看标签:
plt.vlines([1,2,3], 0, 1, label='test')
plt.legend()发布于 2016-02-21 23:39:27
对于此example中行附近的文本,请使用:
vline_value = 3
fig, ax = plt.subplots(figsize=(10,10))
ax.axvline(x=vline_value, ymin=0, ymax=1)
x_bounds = ax.get_xlim()
ax.annotate(s='vline_value', xy =(((vline_value-x_bounds[0])/(x_bounds[1]-x_bounds[0])),1.01), xycoords='axes fraction', verticalalignment='right', horizontalalignment='right bottom' , rotation = 270)
fig.savefig('example')此外,这个简短的脚本还包含更多选项:https://pythonhosted.org/lineid_plot/#
发布于 2014-11-27 01:05:20
这是可行的
plt.plot(x,y)
plt.vlines(x=pah, ymin=0, ymax=0.6, colors='0.75', linestyles='dashed', label='PAHs')
plt.legend()但我不知道这是不是你想要的
https://stackoverflow.com/questions/27154793
复制相似问题