Plotly:Plotly Express遵循哪种颜色循环?

5

我认为默认的颜色循环应该是(某些变体)['blue', 'red', 'green', 'purple', 'orange'],就像下图所示:

图1:

enter image description here

代码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")

至少从省略大洋洲的版本来看,这似乎是循环顺序:

enter image description here

现在,剩下颜色的顺序相同,除了最后一个橙色(只是表明颜色应用不是任意选择的)。

我认为可以使用 plotly.colors.DEFAULT_PLOTLY_COLORS 来检索此信息,它将给出以下结果:

['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)']

但是这些颜色的排列顺序是按照['blue', 'orange', 'green', 'red']...

因此,在px.scatter(gapminder2007, x='gdpPercap', y='lifeExp', color="continent")中设置color="continent"时,plotly express遵循哪种颜色循环呢?

我尝试在help(px.colors)下查找,但没什么用:

plotly.express中plotly.express.colors模块的帮助信息:

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...

1个回答

8
该文档页涵盖了离散的颜色序列:https://plot.ly/python/discrete-color/,并提到默认序列来自于活动模板中的layout.colorway
在名为plotly的默认模板中,此序列可在px.colors.qualitative.Plotly下找到。
该序列为['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接