Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kilala
Resolver I
Resolver I

Power Bi with Python -Heatmap

Hi all. For my learning purpose, I need to create Heatmap chart using Python in Power BI. Supoosedly, this heatmap measures the relationship for sales by state. however, when I tried to run it, it shows state by state. How do I correct this?

(p/s: I'm still beginner in both python and power bi)

 

kilala_0-1615876821904.png

 

this is my python script:

 

# Paste or type your script code here:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(10,6))
sns.heatmap(dataset.corr(), center=0, cmap= 'coolwarm')
ax.set_title('Sales By State')
plt.show()

 

If anyone can help, I would totally appreciate it!

Thanks!

10 REPLIES 10
PhilipTreacy
Super User
Super User

Hi @kilala 

Yes you can do that but you need to supply the sales data.  Have you got such a dataset?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi,

Yes I have daily data sales for 3 years. So, basically I have Order_Year, Sales and State. 

Hi @kilala 

So how do you want to view that data?  A heatmap with daily data for 3 years and 50(?) states will look incredibly busy.

Are you ok to create this heatmap or do you need assistance?

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy ,

Basically, there are around 11 states only, and 3 years sales data.

I want to display data sum of sales data for every year by state. the colour density should be based on the sales amount.

The higher the amount, the darker the colour.

Can we achieve this using heatmap? Hope that you can assist me!

What I have planned to do is

@kilala 

Can you please supply the data, can't do anything without it.

Any reason this has to be done with Python?  There are Heatmap visuals available natively in PBI.

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hello @PhilipTreacy , I have tried to upload the dataset here but it said that excel and .pbix is not supported. So, here I give some sample. Please let me know if there is any other way for me to share the data with you. Thanks!

 

kilala_0-1616002030593.png

 

Hi @kilala 

You can upload the file to OneDrive or Dropbox and share a link to that.

 

Does this have to be done in Python?  Why not use one of the in-built Heatmap visuals?

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi, @PhilipTreacy , here is the link:

https://drive.google.com/file/d/14O7wd9cwh5IxrORW6Gj5ZfHFJOsZXOWL/view?usp=sharing

 

Actually, it is for my learning purpose. I want to know more on what type of visualisation we can do using python in Power BI. I have tried to look up online but there is no further reference on this. Really appriciate your help! 

 

PhilipTreacy
Super User
Super User

Hi @kilala 

There's no data in your code to plot.  The code references a dataset ( dataset.corr() ) but hasn't defined that data.

If you use this code which has a dataset generated using np.random.rand()

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(10,6))
dataset = np.random.rand(10, 12)
sns.heatmap(dataset, center=0, cmap= 'coolwarm')
ax.set_title('Sales By State')
plt.show()

You should end up with this heatmap

pyheatmap.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy , thanks for helping!

I have tried it and it works. But, if possible, i dont want the dataset to be random. i'm thinking to put sales as y-axis, and state as x-axis.  some sort like this:

kilala_0-1615906057686.png

do you have any idea to do so?

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.