[Python] Plotly python histogram add custom colors to distinct values

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

  1. Stack

    Stack Membro Participativo

    I have a dataframe, with 4 distinct values in a column, for each value I need to set the custom colors.

    Below is the sample data

    val,cluster
    118910.000000,3
    71209.000000,2
    25674.666667,0
    109267.666667,3
    8.000000,1


    Below is the code.

    fig = px.histogram(types, x="val",color='cluster')
    fig.show()


    types is the dataframe name from data given

    When I figureI get default colors. Instead I need to get

    0:red

    2:blue

    1:purple

    3:green

    How can I set the custom colors in python plotly for histogram

    Can anyone help on this pls

    Continue reading...

Compartilhe esta Página