我认为默认的颜色循环应该是(某些变体)['blue', 'red', 'green', 'purple', 'orange']
,就像下图所示:
图1:
代码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")
至少从省略大洋洲的版本来看,这似乎是循环顺序:
现在,剩下颜色的顺序相同,除了最后一个橙色(只是表明颜色应用不是任意选择的)。
我认为可以使用 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...