JuliaPlots / JuliaPlots/PlotlyJS.jl

Unable to use ColorSchemes.jl to set a the colorscale when plotting with a dataframe

Open
#446 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
444
Forks
86
PR merge metrics
No merged PRs in 30d

Description

It is extremely useful to be able to set the colorscale when using PlotlyJS for a dataframe with discrete groups, eg:

```julia
plot(df, x = :x, y = :y, color = :group)
```
Specifically I would like to be able to choose one of the colorscales from [ColorSchemes.jl](https://juliagraphics.github.io/ColorSchemes.jl/stable/) for the different groups in the dataframe.

In the documentation for Plotly in Julia, there are few examples showing usage of the `marker.colorscale` property, and my usage of the property is proving ineffective. I cannot find any examples help me in this case. The closest I could find to using `ColorSchemes.jl` with `PlotlyJS.jl` is the example in issue #292, but this doesn't translate to the dataframes case.

The following works, as per the example:

```
data = rand(20) .+ reshape(1:10, 1, :)

plot(
data,
Layout(
colorway=ColorSchemes.tab20.colors
)
)
```
![image](https://user-images.githubusercontent.com/10547901/193075040-d7978036-dd43-4137-ad3d-87d3627532d0.png)

But the following doesn't work, reverting to the default colorscale:

```
df = DataFrame(data, :auto) |> stack

plot(
df,
y = :value,
color = :variable,
marker = attr(
colorscale = ColorSchemes.tab20.colors
)
)
```

![image](https://user-images.githubusercontent.com/10547901/193075387-2c166461-9f36-4234-8283-580c9b4378fb.png)

How can I recreate the first picture using the dataframes syntax?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.