python - Plotly:如何防止旭日图形的最外环颜色变浅?

标签 python plotly plotly-python sunburst-diagram

每当我制作 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()

最佳答案

您正在寻找:

leaf=dict(opacity=1)

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

图 1: leaf=dict(opacity=1)

enter image description here

现在,将其与以下内容进行比较:

图 2: leaf=None

现在,不透明度默认为0.7

enter image description here

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

图 3: colorscale='RdBu'

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

enter image description here

最后,您可以通过 colorscale leaf=dict(opacity=0.2) 两种方式实现。我只是在这里将不透明度设置得很低,以明确说明这一点:

enter image description here

这是您正在寻找的案例的完整代码:

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()

关于python - Plotly:如何防止旭日图形的最外环颜色变浅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61530929/

相关文章:

python - 在python中查找最近编辑的文件

python - 在 Plotly Python 中创建一个文本框

python - 合并子图上的所有 x 标题

Python Plotly - 如何返回范围 slider 的当前位置?

python - 有效地求和一个小的 numpy 数组,在一个巨大的 numpy 数组中广播?

python - 在 dehydrate 中序列化查询集

python - 使用 DictReader 计数

r - 同时使用 formattable 和 plotly

python - plotly:如何向现有图形添加文本?

python - 将绘图工具提示文本颜色设置为与热图的悬停像素相同