Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

python - Plotly: What color cycle does plotly express follow?

I would think that the default color cycle would be (some variants of) ['blue', 'red', 'green', 'purple', 'orange'] like in the plot below:

Plot 1:

enter image description here

Code 1:

import plotly
import plotly.express as px

gapminder = px.data.gapminder()
gapminder2007=gapminder.query("year==2007")
px.scatter(gapminder2007, x='gdpPercap', y='lifeExp', color="continent")

At least that seems to be the order of the cycle since omitting Oceania from the continents will give you this:

enter image description here

Now the order of the remaining colors are the same except for the last orange looking one (just showing that the application of the colors are not aribtrary).

I thought this would be possibleto retrieve using plotly.colors.DEFAULT_PLOTLY_COLORS which will give you:

['rgb(31, 119, 180)',
 'rgb(255, 127, 14)',
 'rgb(44, 160, 44)',
 'rgb(214, 39, 40)',
 'rgb(148, 103, 189)',
 'rgb(140, 86, 75)',
 'rgb(227, 119, 194)',
 'rgb(127, 127, 127)',
 'rgb(188, 189, 34)',
 'rgb(23, 190, 207)']

But those colors are ordered like ['blue', 'orange', 'green', 'red']...

So, what color cycle does plotly express follow when setting for color="continent" in px.scatter(gapminder2007, x='gdpPercap', y='lifeExp', color="continent")?

I tried looking under help(px.colors) too, but that didn't give much:

Help on module plotly.express.colors in plotly.express:

NAME plotly.express.colors

DATA DEFAULT_PLOTLY_COLORS = ['rgb(31, 119, 180)', 'rgb(255, 127, 14)', 'rg... PLOTLY_SCALES = {'Blackbody': [[0, 'rgb(0,0,0)'], [0.2, 'rgb(230,0,0)'... absolute_import = _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This doc page covers discrete color sequences: https://plot.ly/python/discrete-color/ and mentions that the default sequence comes from layout.colorway in the active template.

In the default template called plotly this is the sequence available under px.colors.qualitative.Plotly.

This sequence is ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...