表示条形图的颜色变化

问题描述 投票:0回答:1

如何在下面的代码中将绘图显示的条形图的颜色更改为绿色?

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()
python plotly
1个回答
0
投票

可以完成:-color_discrete_sequence =['green']*3,或-在实例化小节后使用fig.update_traces(marker_color='green')

参考:Community response

© www.soinside.com 2019 - 2024. All rights reserved.