Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a line parallel to y axis in matplotlib?

I want to draw a line at x=c #constant.

This should be pretty straightforward, but how can I do it?

like image 421
Yotam Avatar asked Jan 03 '13 13:01

Yotam


2 Answers

You can use matplotlib.pyplot.axvline().

import matplotlib.pyplot as plt

plt.figure()
plt.axvline(x=0.2)
plt.axvline(x=0.5)
plt.show()

enter image description here

like image 164
Nicolas Avatar answered Nov 15 '22 00:11

Nicolas


Using matplotlib.pyplot's axvline method:

import matplotlib.pyplot as plt

plt.axvline(x=0.5)

enter image description here
You can also set range for the y value:

plt.axvline(x=0.5, ymin=0.2, ymax=0.4)

enter image description here
Default value for ymin = 0 and ymax = 1.

like image 41
shibashis Avatar answered Nov 15 '22 00:11

shibashis