简体   繁体   中英

plot vlines with matplotlib.pyplot

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)

Any ideas? Thanks!

For plotting vertical lines that span the entire plot range, you may use axvline . Your code could then read

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM