[英]Julia: How to change color of a group in plotly scatterplot
Say I have the following example code假设我有以下示例代码
using PlotlyJS
using CSV, DataFrames
df = dataset(DataFrame, "iris")
plot(
df, x=:sepal_width, y=:sepal_length, color=:species,
mode="markers"
)
How could I go about specifying the color for each group eg if I want setosa to be yellow instead?
我怎么能 go 为每个组指定颜色,例如,如果我希望 setosa 改为黄色?
It's exactly this Plotly-Express: How to fix the color mapping when setting color by column name but I need it in julia .正是这个Plotly-Express: How to fix the color mapping when setting color by column name但我在 julia 中需要它。 I could not get the color_discrete_map to work...
我无法让 color_discrete_map 工作......
Not quite as convenient as just setting a color_discrete_map
, but you can do it like this:不像设置
color_discrete_map
那样方便,但你可以这样做:
julia> species_color_map = Dict("setosa" => "yellow", "versicolor" => "aqua", "virginica" => "red")
Dict{String, String} with 3 entries:
"virginica" => "red"
"setosa" => "yellow"
"versicolor" => "aqua"
julia> plot([scatter(
subdf,
x = :sepal_width,
y = :sepal_length,
name = subdf[1, :species],
marker_color = species_color_map[ subdf[1, :species] ],
mode = "markers"
)
for subdf in groupby(df, :species)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.