Closed jfb-h closed 3 years ago
The colorscale should look like this:
cmap = [[0.0, "rgb(255, 0, 0)"],
[0.5, "rgb(0, 255, 0)"],
[1.0, "rgb(0, 0, 255)"]]
i.e. it is defined as an 3-element Array{Array{Any,1},1}
.
You can give the color codes in hex format, too:
plasma = [[0.0, "#0c0786"],
[0.1, "#40039c"],
[0.2, "#6a00a7"],
[0.3, "#8f0da3"],
[0.4, "#b02a8f"],
[0.5, "#cb4777"],
[0.6, "#e06461"],
[0.7, "#f2844b"],
[0.8, "#fca635"],
[0.9, "#fcce25"],
[1.0, "#eff821"]]
The latter example is the default colorscale in the Python version.
Thanks, good to know it should be an array not a dict! However, this does not seem to help with the discrete color mapping problem. Do you know if there's a keyword argument for that also in Julia?
Could you explain what do you mean by discrete colorscale? Is this discrete colorscale https://community.plotly.com/t/colors-for-discrete-ranges-in-heatmaps/7780 what you are looking for?
The python manual on discrete color has a section (pretty far down) which shows how to directly assign colors to levels of a grouping variable. Here's the code snippet:
import plotly.express as px
df = px.data.gapminder().query("year == 2007")
fig = px.bar(df, y="continent", x="pop", color="continent", orientation="h", hover_name="country",
color_discrete_map={
"Europe": "red",
"Asia": "green",
"Americas": "blue",
"Oceania": "goldenrod",
"Africa": "magenta"},
title="Explicit color mapping")
fig.show()
I would like to reproduce that in Julia, i.e. I'm looking for an equivalent to the color_discrete_map
keyword.
Plotly express is a wrapper for plotly.py that exposes a simple syntax for complex charts. Behind the scenes it performs the same computations like in the forum answers above. There is no Julia library that can imitate plotly express functions.
I see, thanks. I thought as PlotlyJS.jl exposes some similar features (e.g. convenience plotting with DataFrames) this might also be available.
Is it possible to use a manual discrete colormap as described in the manual for the python version?
E.g. like so, which errors:
I couldn't find anything in the documentation and tried a bunch of different things but nothing did the trick.