hello, i was trying to learn a bit of julia by doing some plotting although i have encountered some issues while using color palettes:
scatter(df.x, df.y, palette = :tab20b,
xlabel = :x, ylabel = :y)
i have tried several backends and found that color
keyword for palette application could be used although with no succes: all plotted points are of one color
what could i do with that?
thanks
There’s a slight misunderstanding here of how colours are applied in calls to scatter
: every call to scatter
creates a group of points which all have the same colour, by default the first colour of whatever colour palette you are specifying.
If you then call scatter!
again (note the !
, which indicates that the existing plot is modified), the next colour of your chosen colour palette is applied to the next group of points. Consider:
julia> using Plots
julia> scatter(ones(10), rand(10), palette = :tab20b)
julia> scatter!(1 .+ ones(10), rand(10), palette = :tab20b)
julia> scatter!(2 .+ ones(10), rand(10), palette = :tab20b)
julia> scatter!(3 .+ ones(10), rand(10), palette = :tab20b)
julia> scatter!(4 .+ ones(10), rand(10), palette = :tab20b)
julia> scatter!(5 .+ ones(10), rand(10), palette = :tab20b)
which creates:
If you want different colours within one series, you need to specify a vector of colours of the same length as the number of points you’re looking to plot:
julia> scatter(1:10, 1:10, palette = :tab20b, color = 1:10)
hi, thank you for very detailed explanation!
i went further and tried using another vector to color the points by value - is there way to supply palette to do it in Plots.jl ?
i have found a way to simply supply the vector in VegaLite and ggplot although would be nice to stick to one package for plotting