[Python] How to change color in grouped plotly bar plot

Discussão em 'Python' iniciado por Stack, Julho 18, 2025.

  1. Stack

    Stack Membro Participativo

    import plotly.express as px
    import pandas as pd


    data_media_pH = pd.DataFrame([[8.33, 8.36, 8.36], [8.21, 8.18, 8.21], [7.50, 7.56, 7.64]], index=["4 °C", "37 °C", "37 °C + 5 % CO<sub>2"])


    fig_media_pH = px.bar(data_media_pH, barmode="group", color_discrete_sequence=["black"]*3)


    # Adjust layout

    fig_media_pH = fig_media_pH.update_layout(
    showlegend=False,
    xaxis_title_text=None,
    yaxis_title_text="pH",
    width=900,
    height=800,
    margin=dict(t=0, b=0, l=0, r=0),
    yaxis_range=(6.5, 8.6)
    )

    fig_media_pH


    I would like to make each group a different color. Is it possible? I can only change color of everything or of first/second/third column in each group, but not just one group.

    Continue reading...

Compartilhe esta Página