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

Viewed 164

I don't like the leaf categories having a different opacity and I couldn't find the setting to change it.

I found this related topic but I'm using plotly.express instead of plotly.graph_object. Is there a way to change it or do I have to try to change my px-figure into a 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()
2 Answers

This works regardless of whether you've used Plotly Express or Plotly Graph Objects to build your figure:

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

enter image description here

Complete code:

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

As referenced in the related topic, transparency can be controlled with the corresponding graph object.

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

enter image description here

Related