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?
It's exactly this Plotly-Express: How to fix the color mapping when setting color by column name but I need it in julia . I could not get the color_discrete_map to work...
Not quite as convenient as just setting a color_discrete_map
, but you can do it like this:
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)])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.