How To Create A Treemap & Sunburst Chart In Python Using Plotly & Excel
Language:
In this tutorial, I will show you, how to create a Treemap & Sunburst Chart in Python by using the library called Plotly.
The data is coming directly from an excel file. You can do all the changes in the excel file and after running the code again you will have your updated Treemap/Sunburst. The Treemap/Sunburst Chart is interactive and will be saved as an HTML file.
import sys import os import plotly import plotly.express as px import pandas as pd # chdri to current working directory os.chdir(sys.path[0]) # Read Dataframe from Excel file df = pd.read_excel('Tasks.xlsm') # Assign Columns to variables tasks = df['Task'] start = df['Start'] finish = df['Finish'] complete = df['Complete in %'] # Create Gantt Chart fig = px.timeline(df, x_start = start, x_end = finish, y = tasks, color = complete, title = 'Task Overview') # Upade/Change Layout fig.update_layout( title_font_size = 42, font_size = 18, title_font_family = 'Arial', yaxis = {'autorange': 'reversed'}) # Save Graph and Export to HTML plotly.offline.plot(fig, filename='Task_Overview_Gantt.html')