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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Eiki
Frequent Visitor

Python Slicer - Remove line from matplotlib using Slicer Value

I have a plot that looks at daily mean sales for different products, which I made using matplotlib. Now I want a slicer that allows for the removal of unselected lines in the python script. I have the slicer set up but it does not remove the line but does filter the data, which I thought would remove the line but it stays (likley in a default state maybe?). 

 

Here is a code snippit for reference.

 

plt.plot(df['Dates'], df[f'Product{i}'], c = f'{i}')
plt.show()
 
Slicer is set on Product group that contains all the relevant ID numbers - Names dont match but it does seem to filter the data, the data tables are connected in Power Bi Model. I have seen another post similar to this:
 
But this post is not very general enough for me to transfer over to my own challange.
 
Thanks in advance.
1 ACCEPTED SOLUTION
Eiki
Frequent Visitor

I did 'Fix' this by just realizing something about how Python and Power Bi work together.

When you use a slicer it will filter the column you are plotting. There is no need to 'define' a slicer in the python script

First let me say that its a specific way of thinking one needs to approach this combo. In my way of thinking 'you' as the programmer define the behaviour of the slicer by making a connection between the slicer and the python script. This is wrong. Power Bi, when you add a slicer, will filter the data and run the python script again with the new data filtered data frame. So for me I needed to remove some of the programmers thinking and allow Power Bi to do the thing it does best, simplify a lot of tasks.

It isn't a 'programming' solution or software solution - its a 'Aha, thats smart' light bulb monent solution.

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Eiki 

I don't know what line you want to remove.

Could you show an example with pictures?

 

Best Regards

Maggie

I don't have the file right now - but I found a solution. 

 

For the slicer to work in the python script there needs to be a refernce to that file. So there could be an example like this

 

plt.plot(df['date'], df[f'Product{i}'].where(df[f'Product{i}'].isin(ProductList))

 

The ProductList is the list I reference in the slicer so now it works.

 

Thanks again - I found the solution by reading the forum here and Trial and Error

Eiki
Frequent Visitor

I did 'Fix' this by just realizing something about how Python and Power Bi work together.

When you use a slicer it will filter the column you are plotting. There is no need to 'define' a slicer in the python script

First let me say that its a specific way of thinking one needs to approach this combo. In my way of thinking 'you' as the programmer define the behaviour of the slicer by making a connection between the slicer and the python script. This is wrong. Power Bi, when you add a slicer, will filter the data and run the python script again with the new data filtered data frame. So for me I needed to remove some of the programmers thinking and allow Power Bi to do the thing it does best, simplify a lot of tasks.

It isn't a 'programming' solution or software solution - its a 'Aha, thats smart' light bulb monent solution.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.