user1908460
user1908460

Reputation: 193

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!

Upvotes: 13

Views: 28275

Answers (1)

David Zwicker
David Zwicker

Reputation: 24328

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

Upvotes: 29

Related Questions