Python 用 matplotlib.pyplot 绘制 vlines
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16401783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:30:50 来源:igfitidea点击:
plot vlines with matplotlib.pyplot
提问by user1908460
I'm trying to plot vertical lines in a log plot
我正在尝试在对数图中绘制垂直线
xv1 = 10
plt.semilogy(t,P,'b')
plt.semilogy(t,Pb,'r')
plt.vlines(xv1,-1,1,color='k',linestyles='solid')
plt.xlabel('Time [s]')
plt.ylabel('P [Pa]')
plt.grid()
plt.show()
The vlines does not show up in the plot (it does for plt.plot)
vlines 没有出现在图中(它在 plt.plot 中出现)
Any ideas? Thanks!
有任何想法吗?谢谢!
回答by David Zwicker
For plotting vertical lines that span the entire plot range, you may use axvline. Your code could then read
要绘制跨越整个绘图范围的垂直线,您可以使用axvline. 然后您的代码可以读取
xv1 = 10
plt.semilogy(t, P, 'b')
plt.semilogy(t, Pb, 'r')
plt.axvline(xv1, color='k', linestyle='solid')
plt.xlabel('Time [s]')
plt.ylabel('P [Pa]')
plt.grid()
plt.show()

