13

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!

4
  • 1
    Can you also include some (fake?) data with your code? It is hard to test if don't know what you inputs are. Commented May 6, 2013 at 15:21
  • 3
    Why do you use a semi-lograithmic plot (which cannot contain values y=0) and still want your vertical line to extend from -1 to 1? If you want to have a line extending across the entire figure, you should probably use axvline. Commented May 6, 2013 at 15:30
  • @DavidZwicker Completely missed the semi-log.... What version of mpl are you using? There has been some tweaking in how clipping of undefined values is handled in log plots. Commented May 6, 2013 at 16:47
  • As an additional remark: if you do wish to plot data that is also negative on a log axis use ax.set_yscale("symlog"). Commented May 6, 2013 at 22:08

1 Answer 1

29

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.