Iβm a little dumbfounded as to why it is so difficult / obscure to explicitly set colors explicitly (as compared with adopting some color map and assuming there is a column in the data that dictates it). What am I missing?
Seem to me that to explicitly set the color to say BLUE = 'rgb(30,144,255)
fig = px.line(plot_data, x='date',y='quantile',color_discrete_map={'dumb':BLUE})
This assumes you have a column βdumbβ that is constant.
For scatter there seems to be many ways to do it that seem more sensible (though line_color would seem to be a nice argument to have)
fig.add_scatter(df, x="sepal_width", y="sepal_length", line=dict(color="crimson"))
Or
fig.add_scatter( x=df['date'],y=df["price"],mode='markers',marker_color=BLUE)
You can set the mapping to the identity mapping like this:
import plotly.express as px
fig = px.bar(x=["a","b","c"], y=[1,3,2], color=["red", "goldenrod", "#00D"],
color_discrete_map="identity")
fig.show()
and you can set the color to be a constant (with the identity mapping) like this:
import plotly.express as px
fig = px.bar(x=["a","b","c"], y=[1,3,2], color=px.Constant("green"),
color_discrete_map="identity")
fig.show()
Finally, you can always overwrite anything you like with fix.update_traces(line_color="green")
, say
Soβ¦
px.line(x=["a","b","c"], y=[1,3,2]).update_traces(line_color="green")
is the recommendation for px.line?
That works, yep. For a bar chart itβll be fig.update_traces(marker_color="green")
etc etc.
You can also do px.line(x=["a","b","c"], y=[1,3,2], color_discrete_sequence=["green"])
come to think of it. Lots of options
I very much appreciate the quick response.