【问题标题】:Plotly: What color cycle does plotly express follow?情节:情节表达遵循什么颜色循环?
【发布时间】:2020-05-01 02:22:40
【问题描述】:

我认为默认颜色循环将是['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")

至少 似乎 是循环的顺序,因为从大洲省略 Oceania 会给你这个:

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

我认为这可以使用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" 时, 会遵循什么颜色循环?

我也尝试在help(px.colors) 下查找,但效果不大:

关于 plotly.express 中的模块 plotly.express.colors 的帮助:

名字 plotly.express.colors

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

【问题讨论】:

    标签: python plotly


    【解决方案1】:

    此文档页面涵盖离散颜色序列:https://plot.ly/python/discrete-color/,并提到默认序列来自活动模板中的layout.colorway

    在名为plotly 的默认模板中,这是px.colors.qualitative.Plotly 下可用的序列。

    这个序列是['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-23
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 2019-12-05
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多