What is the syntax for vline() in Plots.jl?

There is no documentation and reading the source code didn’t help much.


vline, scatter, heatmap, etc all just pass through to the plot function. You can imagine it looks like:

vline(args...; kw...) = plot(args...; kw..., seriestype = :vline)

There’s nothing special about them… they’re just a convenience.


@tbreloff and so if I want to have a bunch of vertical lines at x1, x2 and x3, what is the syntax?

It may be trivial to you, the person who has written the code, but as a user, I still have no clue of what to pass as args. Should it be a list [x1,x2,x3]? How to control the height of the lines? Etc.


A list [x1,x2,x3] should be fine. If you want to be more precise with how you draw vertical lines, just do it yourself with the normal :path seriestype and separate each line segment with a NaN.

For future reference, the command is:

vline([1,2,3]) # vertical lines at x = 1, 2 and 3.

Notice that you have to pass a 1x1 array if you are interested in a single vertical line (e.g. vline([2])).


Remember, you can also add more lines using the ! variants of the functions, you don’t have to create them all at once.


Hello, and what about wanting to have a specific symbol on the x axis at the point of the vertical line?
I did try something like this but it doesn’t work:

plot!([17], seriestype = :vline, xtick="θ")

(and bdw, would it be possible to get it latex-formatted, e.g. for “\bar θ” ?)

I solved for Latex, but not for the tick on the x axis.
The best I could fins is using annotate!(x,0,text()), but that’s a bit ugly, as I can’t go e.g. to -1 in the y axis:

using Plots, StatPlots, DataFrames
df = DataFrame(a = 1:10, b = 10*rand(10), c = 10 * rand(10))
f = Plots.font("DejaVu Sans", 10)
@df df plot(:a, [:b :c], label=["fitted prices" "obs prices"], xtickfont=f, ytickfont=f, legendfont=f, guidefont=f, titlefont=f) # x = :a, y = [:b :c]. Notice this is two columns!
plot!([5], seriestype="vline")
annotate!(5, 0, text("\$\\bar \\delta \$",f, :left))
plot!([7], seriestype="vline")
annotate!(7, 0, text("\$\\bar \\gamma \$",f, :left))