【问题标题】:How to control the color input of a Sunburst with plotly.graph_objects?如何使用 plotly.graph_objects 控制 Sunburst 的颜色输入?
【发布时间】:2021-04-02 16:12:53
【问题描述】:

我想控制下面 Sunburst 图中每个标签的颜色 - 当使用 plotly.graph_objects 而不是 plotly.express 时。

参见下面documentation 的示例:

import plotly.graph_objects as go

fig =go.Figure(go.Sunburst(
    labels=[ "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents=["",    "Eve",  "Eve",  "Seth", "Seth", "Eve",  "Eve",  "Awan",  "Eve" ],
    values=[  65,    14,     12,     10,     2,      6,      6,      4,       4],
    branchvalues="total",
))
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))

fig.show()

【问题讨论】:

    标签: python colors plotly sunburst-diagram


    【解决方案1】:

    这将允许访问和控制标记:

    import plotly.express as px
    
    greys = px.colors.sequential.Greys
    reds = px.colors.sequential.Reds
    blues = px.colors.sequential.Blues
    greens = px.colors.sequential.Greens
    magents = px.colors.sequential.Magenta
    
    fig.data[0].marker.colors = ['', greys[5], reds[5], reds[6], reds[7], 
                                 blues[5], greens[5], greens[6], magents[5]]
    
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多