有没有办法改变 plotly.express.sunburst 图中叶子的不透明度?

Is there a way to change the opacity of the leafs in a plotly.express.sunburst figure?

我不喜欢具有不同不透明度的叶子类别,我找不到更改它的设置。

我找到了 ,但我使用的是 plotly.express 而不是 plotly.graph_object。有没有办法改变它,或者我是否必须尝试将我的 px-figure 更改为 graph_object? example image

import plotly.express as px
data = dict(
    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])

fig =px.sunburst(
    data,
    names='character',
    parents='parent',
    values='value',
)
fig.show()

如相关主题所述,可以使用相应的图形对象来控制透明度。

import plotly.graph_objects as go

fig =go.Figure(go.Sunburst(
    labels=data['character'],
    parents=data['parent'],
    values=[10, 14, 12, 10, 2, 6, 6, 4, 4],
    leaf=dict(opacity=1),
))

fig.update_layout(margin = dict(t=0, l=0, r=0, b=0))

fig.show()

无论您是否使用 Plotly Express or Plotly Graph Objects 构建您的图形,这都有效:

fig.update_traces(leaf=dict(opacity = 1))

完整代码:

import plotly.express as px
data = dict(
    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])

fig =px.sunburst(
    data,
    names='character',
    parents='parent',
    values='value',
)

fig.update_traces(leaf=dict(opacity = 1))

fig.show()