Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line graph with asymmetric ribbon using Julia-Package "Plots"

I figured out how to plot a line graph with an asymmetric "ribbon" around it with the package "Gadfly" and the following code

x=collect(-10:10);
y=[i^2 for i in -10:10];
ymin = y-5;
ymax = y+10;
using Gadfly
plot(x=x, y=y, ymin=ymin, ymax=ymax, Geom.smooth, Geom.ribbon)

(This was described in this question.)

enter image description here

Now i would like to do the same using the plot function of the "Plots" package. There are options ribbon and fillrange (see http://plots.readthedocs.io/en/latest/examples/pyplot/#layouts-margins-label-rotation-title-location) but I could not figure out how to use them. Is it possible to create such a plot using the "Plots" package and if yes, how?

like image 858
esel Avatar asked Oct 17 '25 10:10

esel


1 Answers

Until I tag a new version of RecipesBase and Plots, you'll need to:

Pkg.checkout("Plots")
Pkg.checkout("RecipesBase")

Now to reproduce your example, you could do:

using Plots; pyplot(border=false)
x = -10:10
y = x .^ 2
plot(x, y, ribbon=(5,10), fillalpha=0.2)

plt

The ribbon arg could take many forms:

plot(x, y, ribbon = 5)  # both sides are 5
plot(x, y, ribbon = 1:3) # both sides cycle through 1:3
plot(x, y, ribbon = (5, 1:3))  # bottom is 5, top cycles 1:3
like image 148
Tom Breloff Avatar answered Oct 20 '25 18:10

Tom Breloff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!