06. Plot Treemap with coffee

Lets load the dataset.

 9 # Libraries
10 import plotly.graph_objects as go
11 import pandas as pd
12
13 from plotly.io import show
14
15 try:
16     __file__
17     TERMINAL = True
18 except:
19     TERMINAL = False
20
21
22 # Define URL
23 URL = 'https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv'
24
25 # Load dataframe
26 df = pd.read_csv(URL)
27
28 # Show
29 if TERMINAL:
30     print("\nDF:")
31     print(df)
32 df
ids labels parents
0 Coffee Coffee Flavors NaN
1 Aromas Aromas Coffee
2 Tastes Tastes Coffee
3 Aromas-Enzymatic Enzymatic Aromas
4 Aromas-Sugar Browning Sugar Browning Aromas
... ... ... ...
92 Pungent-Thyme Thyme Spicy-Pungent
93 Smokey-Tarry Tarry Carbony-Smokey
94 Smokey-Pipe Tobacco Pipe Tobacco Carbony-Smokey
95 Ashy-Burnt Burnt Carbony-Ashy
96 Ashy-Charred Charred Carbony-Ashy

97 rows × 3 columns



37 # Display
38 fig = go.Figure(go.Treemap(
39     ids=df.ids,
40     labels=df.labels,
41     parents=df.parents,
42     pathbar_textfont_size=15,
43     #maxdepth=3,
44     root_color="lightgrey"
45 ))
46
47 # Update
48 fig.update_layout(
49     uniformtext=dict(minsize=10, mode='hide'),
50     margin=dict(t=50, l=25, r=25, b=25)
51 )
52
53 # Show
54 show(fig)

Total running time of the script: ( 0 minutes 0.450 seconds)

Gallery generated by Sphinx-Gallery