Reputation: 730
I am looking for a feature similar to ribbon
that would allow me to fill the area between vertical curves x=x(y)
using Julia Plots. Right now, using ribbon
allows to fill the area between two curves y=y(x)
, like in this example:
using Plots
y(x) = broadcast(sin, x)
x = range(0.0, 3.14, length=30)
plot(x,y(x), ribbon=(zero(x).+0.05, zero(x).+0.1))
savefig("ribbon_example.png")
I am looking for a way to get similar ribbons in the horizontal. I think a similar keyword argument option does not exist yet (see this issue), but I was wondering if other options to resolve this problem exist. For other examples, here is the Python matplotlib implementation of what I would need.
Upvotes: 5
Views: 1335
Reputation: 570
Here is a hacky thing that I've done sometimes. In Julia plots (using the default GR backend anyways) you can usually get it to fill a "shape" -- i.e. here I've implemented it filling vertically between two sine functions:
x=0:π/64:2π
y=sin.(x)
y2=sin.(x).-0.1
plot(y,x,label="curve 1")
plot!(y2,x,label="curve 2")
shapex = vcat(x,[x[end],x[end]],reverse(x),[x[1],x[1]])
shapey = vcat(y,[y[end],y2[end]],reverse(y2),[y2[1],y[1]])
#what i've done above is gone up curve 1, then added two points (defines a line)
#at the ends of curve 1 and curve 2 to connect them, then gone back down curve 2,
#then finally added one more line that jumps back from curve 2 to where we started
#then we have a fully bound shape!
plot!(shapey,shapex,fill=true,label="filled shape",linewidth=0.,fillalpha=0.5,aspect_ratio=:equal,xlims=(-1.5,1.5),size=(360,540))
Which outputs this plot:
Using this you can replicate the matplotlib examples, but you have to think about it step by step and make shapes as you go. Definitely not ideal but it works -- here's a more complicated figure I recently generated for a paper using this approach:
The other thing you could do (which also isn't ideal) is plot your stuff horizontally and fill using the built-in functions, but rotate all the ticks/labels/legend/etc such that at the end you can rotate the saved resulting plot 90 degrees and then it's showing the right behavior...
Upvotes: 1