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
Eiki
Frequent Visitor

Cortador de Python - Eliminar línea de matplotlib usando Slicer Value

Tengo una gráfica que mira las ventas medias diarias de diferentes productos, que hice usando matplotlib. Ahora quiero una segmentación de datos que permita la eliminación de líneas no seleccionadas en el script python. Tengo la segmentación de datos configurada, pero no elimina la línea, pero filtra los datos, que pensé que eliminaría la línea, pero se queda (likley en un estado predeterminado tal vez?).

Aquí hay un snippit de código como referencia.

plt.plot(df['Fechas'], df[f'Producto''], c-f''I'')
plt.show()
La segmentación se establece en el grupo de productos que contiene todos los números de ID relevantes: los nombres no coinciden, pero parece filtrar los datos, las tablas de datos están conectadas en Power Bi Model. He visto otro post similar a este:
Pero este post no es lo suficientemente general como para que me transfiera a mi propio desafío.
Gracias de antemano.
3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hola @Eiki

No sé qué línea quieres quitar.

¿Podría mostrar un ejemplo con imágenes?

Saludos

Maggie

No tengo el archivo en este momento, pero encontré una solución.

Para que la segmentación de datos funcione en la secuencia de comandos de Python debe haber una referencia a ese archivo. Así que podría haber un ejemplo como este

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

ProductList es la lista a la que hago referencia en la segmentación de datos, por lo que ahora funciona.

Gracias de nuevo - Encontré la solución leyendo el foro aquí y Prueba y 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
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.