Note
Click here to download the full example code
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
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)