Skip to content Skip to sidebar Skip to footer

Plotly: Preventing Bars On Bar Chart From Changing Color Based On Background Color

I have a set of sales data in a Pandas dataframe df that looks similar to the following: import pandas as pd df = pd.DataFrame({'date':['2021-01-04', '2021-01-05', '2021-01-06', '

Solution 1:

There is the option to add layer='below' to the add_hrect.

fig = px.bar(df, x='date', y='sales')

fig.add_hrect(y0=0, y1=2200, line_width=0, fillcolor="red", opacity=0.25, layer='below')
fig.add_hrect(y0=2200, y1=5000, line_width=0, fillcolor="yellow", opacity=0.25, layer='below')
fig.add_hrect(y0=5000, y1=10000, line_width=0, fillcolor="green", opacity=0.25, layer='below')

Post a Comment for "Plotly: Preventing Bars On Bar Chart From Changing Color Based On Background Color"