# PyPlot add vertical line

**URL:** <https://discourse.julialang.org/t/pyplot-add-vertical-line/35632>\
**Category:** New to Julia\
**Created:** [March 6, 2020, 10:00am UTC](https://discourse.julialang.org/t/pyplot-add-vertical-line/35632 "2020-03-06T10:00:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [March 6, 2020, 10:00am UTC](https://discourse.julialang.org/t/pyplot-add-vertical-line/35632/1 "2020-03-06T10:00:39Z")

</div>

Hello,  
I would like to add 1. a single vertical line and 2. a series of vertical lines to a PyPlot chart. I have, let’s say, an x value of 38, how do I plot a vertical line on that point?  
And if I create a vector with multiples of that value so that X = [0, 1, 2, 3]\*38, can I plot that in a single line?  
Thank you

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [March 6, 2020, 10:12am UTC](https://discourse.julialang.org/t/pyplot-add-vertical-line/35632/2 "2020-03-06T10:12:59Z")

</div>

My method is to plot them all in one go. Each vertical line consists of three `x` values and three `y` values. The first two `x` values are the same, the position of the vertical line. The third one doesn’t matter, I usually use a NaN. The first `y` value is the minimum of the plot or the minimum `y` limit. The second `y` value is the maximum of the plot or the maximum of the `y` limit. The third value is a NaN. This prevents each vertical line from being connected.

---

<div class="post-metadata">

**Author:** ![orialb](https://avatars.discourse-cdn.com/v4/letter/o/65b543/32.png) [@orialb](https://discourse.julialang.org/u/orialb)\
**Post date:** [March 6, 2020, 12:42pm UTC](https://discourse.julialang.org/t/pyplot-add-vertical-line/35632/3 "2020-03-06T12:42:39Z")

</div>

Take a look at the [vlines](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.vlines.html?highlight=vlines#matplotlib.pyplot.vlines) function which does exactly what you are looking for.

P.s: `axvlines` is also relevant if you want the line to automatically cover the whole y-range. In general whenever you have a question about how to do something in `PyPlot` I would recommend first trying to look up in your favorite search engine `"matplotlib DO SOMETHING"`, as there is a good chance that someone already answered this question in the python community (and the syntax from within Julia is almost identical) . For example in this case `"matplotlib add vertical line"` will lead you to the answer.
