How to make a dynamic heatmap chart in Excel with Python

You will build a heatmap in Excel that updates when your data changes, using Python inside Excel. It suits Excel users who have the Python feature switched on and know a little Python. You need a Microsoft 365 subscription and a table of numbers.

YouTube video: How to create a dynamic heatmap chart in Excel using Python! #excel #spreadsheets #python

Caption availability is unknown. Check the CC control in the YouTube player.

Video length
1 min 3 s
Time to do it
20 minutes
Difficulty
Medium
Steps
8

What you need

Steps

  1. Open Excel and put your data in a table. Use Insert > Table so the range grows when you add rows.

  2. Click a blank cell, then choose Formulas > Insert Python to start a Python cell.

  3. Turn the table into a DataFrame by typing xl("Table1", headers=True) in the Python cell and press Ctrl+Enter.

  4. Import the libraries with import pandas as pd and import matplotlib.pyplot as plt.

  5. Reshape the data if needed with df.pivot, so rows and columns form the grid of the heatmap.

  6. Draw the chart with plt.imshow or a seaborn heatmap, then add a colour bar with plt.colorbar().

  7. Return the figure with plt.show() so Excel shows the chart on the sheet next to the Python cell.

  8. Change a value in the table and press Ctrl+Alt+F9 to recalculate. The heatmap redraws with the new numbers.

Tips and common mistakes

Keep the data as an Excel table, otherwise new rows will not appear in the heatmap.

Use a single colour scale and label the axes so readers can tell high values from low ones.

If the Python cell shows an error, check that Python is enabled under Formulas and that the table name matches.

Questions

Do I need a subscription for Python in Excel?

Yes. Python in Excel is part of a Microsoft 365 subscription and runs in the cloud, so you need an internet connection.

Can I use this in Google Sheets?

No. Google Sheets has no built-in Python. Use conditional formatting colour scales there, or build the heatmap in Excel.

Will the chart update automatically?

It updates when the workbook recalculates. Press Ctrl+Alt+F9 to force a full recalculation after editing the data.

The notes are drafted automatically from video details and general task knowledge. How the guide was prepared

Report a correction

More in Apps & Software

See all