Reputation: 1029
Is it possible to control the alpha property (opacity, or transparency) when plotting with Gadfly? I am attempting to plot a comparison of distributions. Any info would be appreciated.
Upvotes: 4
Views: 1168
Reputation: 4406
It is possible with Geom.ribbon
. The following code copy-pastes the plot from nabble.com and uses the Geom.ribbon opacity
issue on Github:
using Gadfly, DataFrames, Distributions
d1 = Normal(-1);
d2 = Normal(1);
x = -4:0.01:4
y1 = pdf(d1, x);
y2 = pdf(d2, x);
df1 = DataFrame(x = x, y = y1, ymin = 0.0, ymax = y1, d = "d1");
df2 = DataFrame(x = x, y = y2, ymin = 0.0, ymax = y2, d = "d2");
df = vcat(df1, df2)
# No transparency
p1 = plot(df, x = :x, y = :y, ymin = :ymin, ymax = :ymax, color = :d, Geom.line, Geom.ribbon)
# With transparency
p2 = plot(df, x = :x, y = :y, ymin = :ymin, ymax = :ymax, color = :d, Geom.line, Geom.ribbon),
Theme(lowlight_color=c->RGBA{Float32}(c.r, c.g, c.b, 0.2)))
draw(PNG("test1.png", 12cm, 6cm), p1)
draw(PNG("test2.png", 12cm, 6cm), p2)
Plot without transparency:
Plot with transparency:
Upvotes: 0
Reputation: 11654
Not yet, but it is a planned feature that seems close to being added.
Upvotes: 1