Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Filled Area Plots - fill color depends on value

Hi, i would like to have a Filled Area Plot, where the fill color depends on a limit value as shown on the picture:

import pandas as pd
data = [[1, 22], [2, 33], [3, 45], [4, 51], [5, 18], [6, 30], [7, 35], [8, 42]]
df = pd.DataFrame(data, columns = [‘Col1’, ‘Col2’])
Limit = 40

I found this thread, but I am not sure, how to define two filled areas.
https://community.plotly.com/t/fill-according-to-y-values/7414

Ok, i finally understand the topic, but somehow it is not exactly, what i was looking for:

Replacing values greater than a number in pandas dataframe:

df[‘Col3’].values[df[‘Col2’] > Limit] = Limit

After that plot the both filled area plots (tozeroy & tonexty):

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Scatter(x=df[‘Col1’], y=df[‘Col3’], fill=‘tozeroy’,
mode=‘none’ # override default markers+lines
))
fig.add_trace(go.Scatter(x=df[‘Col1’], y=df[‘Col2’], fill=‘tonexty’,
mode= ‘none’))

fig.show()

Is there any better way, how to reach the visualisation from the reference picture?