[Python] Is it possible to automate color code for stacked column plot in Power BI and have...

Discussão em 'Python' iniciado por Stack, Maio 31, 2025.

  1. Stack

    Stack Membro Participativo

    I have a very simple fruit_sales dataset as shown:

    Fruit Sales
    Apple 10
    Banana 40
    Guava 20

    I imported this data from an Excel file in Power BI. And I plotted it as a stacked column chart as shown. I dragged Sales column in Y-axis and Fruit column in Legend. [​IMG]

    In the Visualization menu, I don't see the option for applying a custom function fx to automate this. It can only be done manually. [​IMG]

    I want to automate the color code for this plot such that Apple is red, Banana is yellow, and Guava is Green in the column. I created a custom column for this as shown: color_code_column = SWITCH( fruit_sales[Fruit], "Apple", "#ff0000", "Banana", "#ffff00", "Guava", "#008000", BLANK() )

    and used this custom column for legend.

    However, the colors that appear in the plot are not correct, plus I am also not getting the fruit names in the labels, it's the color codes. [​IMG]

    Is it possible to get correct column plot with proper colors and labels similar to Python?

    Continue reading...

Compartilhe esta Página