使用Gadfly绘图时是否可以控制alpha属性(不透明度或透明度)?我试图绘制分布的比较。任何信息将不胜感激。
答案 0 :(得分:1)
答案 1 :(得分:0)
Geom.ribbon
是可能的。以下代码从nabble.com复制粘贴该图,并使用Geom.ribbon opacity
问题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)
没有透明度的图
具有透明度的图