情节:如何防止一个阳光人物的最外环变浅?

2024-09-28 22:05:54 发布

您现在位置:Python中文网/ 问答频道 /正文

每当我制作一张绘出的太阳暴击图(我使用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()

Tags: 标记margingo标准图表figplotlyeve
1条回答
网友
1楼 · 发布于 2024-09-28 22:05:54

您正在寻找:

leaf=dict(opacity=1)

这将设置树叶的不透明度。对于指定的colorscale,它默认为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'

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

enter image description here

最后,您可以通过colorscaleleaf=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()

相关问题 更多 >