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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
perezco
Advocate III
Advocate III

Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

This is a basic python headmap script visual in Power BI.

I am looking to apply a filter to this python script code bellow.

How can be this be filter by slicer(dimension) in this correlation Heatmap code? Below is the code I have written.

------

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset = pandas.DataFrame(A_DENO, A_NUM, _Acceptable,_S_ASIS,_A_ASIS, _Offered,_Region)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import pandas as pd # for data analysis
import matplotlib.pyplot as plt
import seaborn as sns
# Compute the correlation matrix #filter by Region # HERE NEED TO MAKE DATASET3.['REGION'] ###dataset2= dataset.loc[dataset.Region =='North America' ]
corr = dataset2.corr() ##plt.figure(figsize=(17,17))
sns.heatmap(corr,cmap='coolwarm', annot = True, fmt='.5g',linewidth =1.9) #plt.title("Correlation HeatMap", fontsize = 16)
plt.xlabel("Features", fontsize = 10)
plt.ylabel("Features", fontsize = 10)
plt.show()

------

The dataset contains several columns.

But I took the picture for those I am interest to work in this python script.

 

 

cluster.1579892631.png

 

_S_ASIS=
DIVIDE( SUM('Cad_KPI'[_Acceptable]), SUM('Cad_KPI'[_Offered]))*100
_A_ASIS
=DIVIDE(DIVIDE( SUM('Cad_KPI'[_A_NUM]), SUM('Cad_KPI'[_A_DENO])), 60)

 Sample data in this image.

 

cluster.p.png

1 ACCEPTED SOLUTION

Hi @perezco,

 

I think your heat map needs at least two lines of data.

PythonHeatmap.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

7 REPLIES 7

Hi @perezco ,

 

Power BI replots the Python visual, whenever a data change occurs. (filtering)

The Python visual always only receives the filtered data.

https://docs.microsoft.com/en-us/power-bi/desktop-python-visuals

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support. 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


right, @mwegener .... yes I can used the filters section for the Vizulation from the left but I need is to use slicer filter.

 

 

example for Bar chart code:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset = pandas.DataFrame(_Region, _A_DENO))
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import pandas
import matplotlib.pyplot as plt
plt.bar(dataset['_Region'],dataset['_A_DENO'])
plt.show()
 
 
 
Here in this image allow mhas the control that I need but for a chart bar
cluster.1580150670.png

Hi @perezco ,

 

could you share your sample pbix?

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


@mwegener 

Here is the file

https://1drv.ms/f/s!Au2MNJlU7lrShnbliSMHNzsD73W4

 

Thanks for any advice.

Hi @perezco,

 

I think your heat map needs at least two lines of data.

PythonHeatmap.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


@mwegener 

 

yes, I am aware this demo file brings few records.. But I see that work fine with the filters slicers.

 

thanks

 

 

Hi @perezco ,

 

If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.