Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 782
user1908460 Avatar asked May 06 '13 15:05

user1908460


People also ask

How do I plot a horizontal line in Matplotlib?

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.

What is Matplotlib Axvline?

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)


1 Answers

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()
like image 59
David Zwicker Avatar answered Oct 13 '22 06:10

David Zwicker