【问题标题】:Plotly: How to prevent the outermost ring of a sunburst figure from being a lighter shade?Plotly:如何防止旭日形图案的最外圈颜色变浅?
【发布时间】:2020-04-30 19:06:19
【问题描述】:

每当我制作 Plotly 旭日形图(我使用 Python)时,最外面的“圆”或环比其他旭日形环要轻得多。我怎样才能让这个环的阴影与图表的其余部分相同?

如您所见,标记为 Bb5 的片段比其他片段更轻。

我正在使用标准的 Plotly sunburst 代码。简单的例子(无论如何都会变浅):

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=[10, 14, 12, 10, 2, 6, 6, 4, 4],
))
# Update layout for tight margin
# See https://plotly.com/python/creating-and-updating-figures/
fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))

fig.show()

【问题讨论】:

    标签: python plotly plotly-python sunburst-diagram


    【解决方案1】:

    您正在寻找:

    leaf=dict(opacity=1)
    

    这会设置叶子的不透明度。指定色阶默认为1,否则默认为0.7

    情节1: leaf=dict(opacity=1)

    现在,比较一下:

    情节2: leaf=None

    现在,不透明度默认为0.7

    看看当你为colorscale指定一个值时会发生什么:

    情节3: colorscale='RdBu'

    如果省略叶子参数,则该图默认为叶子的不透明度 = 1:

    最后,您可以同时使用colorscale leaf=dict(opacity=0.2)。我只是在这里将不透明度设置得很低以明确一点:

    这是您要查找的案例的完整代码:

    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=[10, 14, 12, 10, 2, 6, 6, 4, 4],
        leaf=dict(opacity=1),
        #marker=dict(colorscale='RdBu')
    ))
    
    fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))
    
    fig.show()
    

    【讨论】:

    • @vestland 的问题:你知道是否有办法利用leaf 或其他属性来操纵旭日形图不同环的不透明度?我对将中心环和最外环设置为完全不透明但让中间环保持较浅阴影的方法特别感兴趣。换句话说,有没有办法调整分支不透明度?
    猜你喜欢
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 2021-09-09
    • 2020-11-14
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多