[Python] Plotly express bar chart colour change

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    How can I change the colour of the plotly express bar-chart to green in the following code?

    import plotly.express as px
    import pandas as pd

    # prepare the dataframe
    df = pd.DataFrame(dict(
    x=[1, 2, 3],
    y=[1, 3, 2]
    ))


    # prepare the layout
    title = "A Bar Chart from Plotly Express"

    fig = px.bar(df,
    x='x', y='y', # data from df columns
    color= pd.Series('green', index=range(len(df))), # does not work
    title=title,
    labels={'x': 'Some X', 'y':'Some Y'})
    fig.show()

    Continue reading...

Compartilhe esta Página