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!
In matplotlib, if you want to draw a horizontal line with full width simply use the axhline() method. You can also use the hlines() method to draw a full-width horizontal line but in this method, you have to set xmin and xmax to full width.
axvline() Function. The Axes. axvline() function in axes module of matplotlib library is used to add a vertical line across the axis. Syntax: Axes.axvline(self, x=0, ymin=0, ymax=1, **kwargs)
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With