I created a nice px.sunburst
graph. Now I want to format the single "nodes" of the sunburst. For instance I want to change fontsize of the main "node" and make it bold or change the color of a specific "node".
Unfrotunately I did not find such features in the Sunburst documentation.
uniformtext
only formats the whole text and with color
and color_discrete_map
I cannot control single nodes:
Pseude 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',
color='parent',
color_discrete_map={
'': 'rgb(56, 75, 126)',
'Eve': 'lightgreen',
'Cain': 'black',
'Enos': 'black',
},
)
fig.show()
I did not find such features in the documentation.
To change the color of these sunburst's nodes separately you need to set color='character'
. Keeping your discrete map this would result in:
For the font size, I'd let plotly work this out, because behind the scenes it's adjusting font size so that it can fit in its area. That being said, you can set a font size several ways to maybe achieve what your looking for:
Using fig.update_traces(textfont=dict(size=[20]))
will set the first item's font size.
To adjust more nodes expand the array as necessary to align with items in character
, for instance:
fig.update_traces(textfont=dict(family=['Arial','Courier New'],size=[8,20,8]))
will set the second item in character
to Courier New
it's font to 20 and the first and third elements font size to 8.
Finally, to bring it all together (and this may depend on what fonts you have available) to set Eve's font size and make it bold:
fig.update_traces(textfont=dict(family=['Arial Black', 'Arial'],size=[15]))