更改绘图条形图中的颜色

时间:2021-01-16 02:53:23

标签: python pandas plotly plotly-express

我如何改变在条形图中以图形方式表达特定条形的颜色。 例如,我想将颜色更改为紫色,更改为德国牧羊犬(来自品种)。

fig = px.bar(data_frame=df, x="quantity", y="dogs", orientation='h', color='dogs',hover_name='breed',)

谢谢。

1 个答案:

答案 0 :(得分:2)

您可以像这样制作 discrete_color_map 字典:

color_discrete_map = {'German Shephard': 'rgb(255,0,0)'}

并在创建条形图时将其传递到您的参数中,如下所示:

fig = px.bar(data_frame=df, x="quantity", y="dogs", orientation='h', color='dogs',hover_name='breed',color_discrete_map = color_discrete_map)

这是documentation

相关问题