sunburst, I can't pass the parameter to label my sectors with the count of occurrences, only parents' names

50 Views Asked by At
import plotly.express as px
import pandas as pd
df = pd.read_csv('C:\\SIGLOC\\statbatinatureVE.csv',sep=';', encoding='latin-1')
print(df)

fig = px.sunburst(df, path=['VE', 'NAT'], values='COUNT')
fig.show()

My data:

VE;NAT;COUNT
Canal de l'Est;Bâtiment;724
Canal entre Champagne et Bourgogne;Bâtiment;616
Canal de l'Est;Maison;326
Canal de la Marne au Rhin;Bâtiment;578
Canal de la Marne au Rhin, branche Est;Bâtiment;2
Moselle;Bâtiment;190
Moselle;Maison;106
Canal de la Marne au Rhin;Maison;144
Canal entre Champagne et Bourgogne;Maison;216
inconnu;Maison;28
Canal des Vosges (ex Canal de l'Est, branche Sud);Maison;2
Rivière Moselle;Maison;6
Moselle canalisée;Bâtiment;6
inconnu;Bâtiment;38
Canal des Ardennes;Bâtiment;124
Canal des Ardennes;Maison;34
Canal de Jouy;Bâtiment;18
Canal des Vosges;Bâtiment;4
Meuse;Bâtiment;2
Canal de la Meuse (ex Canal de l'Est, branche Nord);Bâtiment;8
Canal de la Marne au Rhin, branche Ouest;Bâtiment;4
Canal de l'Est;inconnu;2
Canal de l'Est;Patrimoine historique;2
Canal entre Champagne et Bourgogne;inconnu;2
Meuse;Maison;2
Meurthe;Bâtiment;2
Canal de la Marne au Rhin;inconnu;2
Canal latéral à la Marne;Maison;2
Canal entre Champagne et Bourgogne;Patrimoine historique;2
Moselle;inconnu;2
Canal de Jouy;Maison;2

Results:

two-level pie chart where the outer chart subdivides the slices in the inner chart

I've tried with names='count' without success, like parameter of sunburst process

1

There are 1 best solutions below

0
r-beginners On

The method described in the comments would add even more circles. The labels and numbers can be displayed by updating the information in the text available in the graph object. There are several other configuration values. The values that can be set are as follows. ['label', 'text', 'value', 'current path', 'percent root', 'percent entry', 'percent parent']

import plotly.express as px

fig = px.sunburst(df, path=['VE', 'NAT'], values='COUNT')
fig.update_traces(textinfo='label+value')
fig.show()

enter image description here