Plots.jl: Drawing a span

Created on 31 Jan 2018  路  5Comments  路  Source: JuliaPlots/Plots.jl

Is there a Plots.jl equivalent of axvspan? I'd like to highlight a region of my plot. vline! looked promising at first, but its width parameter is in pixel, whereas I would like it in x-coordinates (as in matplotlib)

Most helpful comment

As of now, I'm afraid that, to replicate the python example, you'd have to do:

plt = plot(0:9)
x1, x2 = 3, 6
y1, y2 = ylims(plt)
plot!(plt, [x1, x2, x2, x1], [y1, y1, y2, y2], color="red", alpha=0.5, seriestype = :shape)

Maybe it'd be nice to have a rectangle as well as a vspan and hspan seriestype, which could be implemented using shape.

All 5 comments

As of now, I'm afraid that, to replicate the python example, you'd have to do:

plt = plot(0:9)
x1, x2 = 3, 6
y1, y2 = ylims(plt)
plot!(plt, [x1, x2, x2, x1], [y1, y1, y2, y2], color="red", alpha=0.5, seriestype = :shape)

Maybe it'd be nice to have a rectangle as well as a vspan and hspan seriestype, which could be implemented using shape.

Thank you, that works! I used linealpha=0 to take out the hard edges.

Glad it worked for you. Better to keep the issue open though as it's a good candidate for a series recipe potentially called vspan (and hspan). The recipe could probably already have the transparency default to 0.5 so that the new syntax would be:

plt = plot(0:9)
plot!([3, 6], color="red", seriestype = :vspan)

Better to keep the issue

Agreed; your solution is perfect for what I need, but the fact that the rectangles are not infinite in the y-axis shows up when panning/zooming-out.

You can now use vspan and hspan. See #1445

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jebej picture jebej  路  4Comments

asinghvi17 picture asinghvi17  路  3Comments

nebuta picture nebuta  路  3Comments

PallHaraldsson picture PallHaraldsson  路  4Comments

dancsi picture dancsi  路  4Comments