我正在使用Julia中的Gadfly绘制数据。 我有x =一组浮点数,以及几个匹配长度的y1、y2、y3等。如何在一个Gadfly图中将所有点(x,y1)绘制为绿色,(x,y2)绘制为红色,以此类推?
x
,y
和group
,并使用group作为颜色美学。# Sample data
n = 10
x = collect(1:n)
y1 = rand(n)
y2 = rand(n)
y3 = rand(n)
# Put the data in a DataFrame
using DataFrames
d = DataFrame(
x = vcat(x,x,x),
y = vcat(y1,y2,y3),
group = vcat( rep("1",n), rep("2",n), rep("3",n) )
)
# Plot
using Gadfly
plot(
d,
x=:x, y=:y, color=:group,
Geom.point,
Scale.discrete_color_manual("green","red","blue")
)
如评论中所建议的,您也可以使用层:
plot(
layer(x=x, y=y1, Geom.point, Theme(default_color=color("green"))),
layer(x=x, y=y2, Geom.point, Theme(default_color=color("red"))),
layer(x=x, y=y3, Geom.point, Theme(default_color=color("blue")))
)
julia> using Plots; scatter(rand(10,3), c=[:green,:red,:blue])