I am struggling to plot two different (x,y) lines together with a single plot
command and the default color palette, since apparently I can’t give the layers label = "Data Label"
like in Plots.jl. What is the best way to do this? Is it easier in Makie or VegaLite?
using Gadfly
x1=0:0.1:5
x2=0:0.5:5
y1=sin.(x1)
y2=sin.(x2).+0.2
layer1 = layer(x=x1, y=y1, Geom.line, color=[1])
layer2 = layer(x=x2, y=y2, Geom.line, color=[2])
plot(layer1,
layer2,
style(line_width=2pt),
Guide.xlabel("x"),
Guide.ylabel("y"),
Guide.manual_color_key("",["Theory","Data"]))
Similar Discourse Post
using DataFrames
df = DataFrame(x=[x1; x2],
y=[y1; y2],
kind=[repeat(["Theory"], length(x1));
repeat(["Data"], length(x2))])
plot(df, x=:x, y=:y, color=:kind, Geom.line)
The top plot can be done like this too:
layer1 = layer(x=x1, y=y1, Geom.line, color=["Theory"])
layer2 = layer(x=x2, y=y2, Geom.line, color=["Data"])
p = plot(layer1, layer2, style(line_width=2pt),
Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(""))
2 Likes
Fontconfig package (required for saving) breaks the plot.
I can reproduce the plot above.
add Cairo, Fontconfig
p = plot(layer1, layer2, style(line_width=2pt), Guide.xlabel("x"), Guide.ylabel("y"), Guide.colorkey(""))
draw(PNG("Test.png", 6inch, 4inch), p)
i can’t reproduce. here’s my PNG:
what version of Gadfly, Julia, etc. and what OS are you using?
I get the same behavior using Pluto, WSL terminal, and VSCode for Windows.
Newest version for all:
Julia: 1.7.2
Gadfly: 1.3.4
Cairo: 1.0.5
Fontconfig: 0.4.0
monty
June 17, 2022, 4:10pm
8
@bjarthur I hope this gets resolved. I am using the same versions and I have the same problem.
monty
June 22, 2022, 12:33pm
9
@bjarthur any updates on this major problem with plotting gadfly figures!?