Create a Treemap in Excel using Python

Follow this article to create a Treemap in Excel using Python. It has details for setting the IDE, a list of steps, and a sample code for adding a Treemap in Excel using Python. The sample code demonstrates the complete process by adding the sample data and add the customized chart for desired visualization.

Steps to Create Tree Map in Excel using Python

  1. Configure your environment to use Aspose.Cells for Python via Java
  2. Start JVM in jpype, import necessary classes, and load a license
  3. Create a Workbook, access a sheet, and use the Cells collection to insert sample hierarchical data
  4. Add border and other custom settings to the existing data table
  5. Add a Treemap chart, set the title, set the series values, category, and flags for values and categories on the chart
  6. Set the legend position on the chart
  7. Save the output Excel file with the Treemap chart on the disk

The above steps summarized the process to create a Tree map using Python. Create an Excel file, access a sheet, get the cells collection, add hierarchical data in the sheet, and create a chart using the ChartType.TREEMAP enumerator. Finally, set the chart series data and other parameters of the chart before saving the resultant Excel file.

Code to Generate Treemap Chart in Excel using Python

The aforementioned sample code demonstrates the creation of the Excel Treemap chart. You can create other types of charts, such as WATERFALL, PARETO_LINE, SURFACE_3D, PIE, LINE, and BUBBLE, etc. The Chart class represents a single Excel chart — letting you define its data series, axes, title, style, and layout, and manipulate or export it (e.g., save as image or PDF).

This article has described the process to create a Treemap. To generate a Sunburst chart, refer to the article Create a Sunburst chart in Excel using Python.