Python Forum
I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped.
#2
In Power BI, when you filter data, it affects the dataset being passed to the Python script, resulting in changes in the plotted graph. However, you can potentially work around this issue by passing all data points to the Python script and implementing the filtering within the script itself based on the filters applied in Power BI.

Here's how you might adjust your script to handle this:
  • Pass all the data points to Python script from Power BI.
    Modify the quadrant_chart function to filter data based on the criteria specified in Power BI filters.
    Ensure that your Power BI filters are set up to interact with the Python script properly.

here is modified 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(Name, Home Function, GRUE Category , Type of Move)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

def quadrant_chart(XXXXX_1, XXXXX_2, Name, TiR, TiS, TiG, xtick_labels=None, ytick_labels=None, ax=None):
# Ensure XXXXX_1 and XXXXX_2 have the same length
if len(XXXXX_1) != len(XXXXX_2):
raise ValueError("XXXXX_1 and XXXXX_2 must have the same length")

# Convert 'Yes' to 10 and 'NO' to 1 in both columns
XXXXX_1[XXXXX_1 == 'Yes'] = 10
XXXXX_1[XXXXX_1 == 'NO'] = 1

XXXXX_2[XXXXX_2 == 'Yes'] = 10
XXXXX_2[XXXXX_2 == 'NO'] = 1

# make the data easier to work with by putting it in a dataframe
data = pd.DataFrame({'XXXXX_1': XXXXX_1, 'XXXXX_2': XXXXX_2, 'Name': Name, 'TiR': TiR, 'TiS': TiS, 'TiG': TiG})

# Apply filtering based on criteria from Power BI filters
# Example: If 'Filter_Column' is a column in your dataset that is filtered in Power BI
# You can apply the filter like this:
# data = data[data['Filter_Column'] == 'Desired_Value']

# let the user specify their own axes
ax = ax if ax else plt.axes()

# rest of your plotting code...
# (unchanged from your original script)

# Assuming the data is already loaded into Power BI and accessible via the DataFrame 'dataset'
# Fetch relevant columns from the dataset
XXXXX_1 = dataset['XXXXX_1'].to_numpy()
XXXXX_2 = dataset['XXXXX_2'].to_numpy()
Name = dataset['Name'].to_list()
TiR = dataset['TiR'].to_numpy()
TiS = dataset['TiS'].to_numpy()
TiG = dataset['TiG'].to_numpy()

# Call quadrant_chart function with error handling
try:
quadrant_chart(
XXXXX_1=XXXXX_1,
XXXXX_2=XXXXX_2,
Name=Name,
TiR=TiR,
TiS=TiS,
TiG=TiG,
xtick_labels=['PROMOTION', 'LATERAL MOVE'],
ytick_labels=['GROW', 'EXPORT']
)
except ValueError as e:
print("Error:", e)

i hope it will work for you

Best regard
Danish hafeez | QA Assistant
buran write Mar-05-2024, 07:00 AM:
Please, stop sharing spam link in your signature. This is not advertising platform.
Reply


Messages In This Thread
RE: I’m trying to create a Power BI Matplotlib quadrant chart and I’m a little stumped. - by Danishhafeez - Mar-04-2024, 06:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Visualizing musician chart performance and ranking using pandas and matplotlib Drone4four 5 510 May-12-2024, 02:23 AM
Last Post: Drone4four
  matplotlib.pyplot functions create new figures instead of applying to the current one karkas 2 2,169 Jul-09-2020, 08:32 AM
Last Post: karkas
  Rename labels of a bar chart Matplotlib smalatray 1 4,423 Jul-01-2020, 01:48 AM
Last Post: hussainmujtaba
  Prediction of Coal Fire Power Plant Pollutants Emission Dalpi 2 2,225 May-08-2020, 06:28 PM
Last Post: Dalpi
  Matplotlib bar chart ollarch 0 1,447 Mar-04-2020, 10:45 AM
Last Post: ollarch
  How to create matplotlib subplots from figures vitaly 3 3,209 Mar-02-2020, 12:58 AM
Last Post: scidam
  Spacing pie chart colours evenly in matplotlib? Giovanni_diJacopo 1 3,374 Jul-12-2019, 12:31 PM
Last Post: scidam
  how can I create a recursive graphic with matplotlib royer14 3 3,841 Nov-22-2018, 05:00 PM
Last Post: Gribouillis
  how can I create graphics using matplotlib royer14 8 4,320 Nov-21-2018, 07:02 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020