Note
Click here to download the full example code
06. Coffee flavours (treemap)
This example uses the pandas and Plotly libraries to create and display an interactive treemap visualization of coffee flavors.
Lets load the dataset.
13 # Libraries
14 import plotly.graph_objects as go
15 import pandas as pd
16
17 from plotly.io import show
18
19 try:
20 __file__
21 TERMINAL = True
22 except:
23 TERMINAL = False
24
25
26 # Define URL
27 URL = 'https://raw.githubusercontent.com/plotly/datasets/96c0bd/sunburst-coffee-flavors-complete.csv'
28
29 # Load DataFrame
30 df = pd.read_csv(URL)
31
32 # Show
33 if TERMINAL:
34 print("\nDataFrame:")
35 print(df)
36 df
41 # Display
42 fig = go.Figure(go.Treemap(
43 ids=df.ids,
44 labels=df.labels,
45 parents=df.parents,
46 pathbar_textfont_size=15,
47 #maxdepth=3,
48 root_color="lightgrey"
49 ))
50
51 # Update
52 fig.update_layout(
53 uniformtext=dict(minsize=10, mode='hide'),
54 margin=dict(t=50, l=25, r=25, b=25)
55 )
56
57 # Show
58 show(fig)
Total running time of the script: ( 0 minutes 3.226 seconds)