plotly.graph_object.Scatter plot fill color map

@AIMPED Thanks again for your help. Uisng a contour plot and borrowing your codes, I am able to make a plot very similar to what you did above:

import plotly.graph_objects as go
import numpy as np

# data for overlay
lowT = np.asarray([35, 32, 41, 70, 79, 60, 38])
hiT = np.asarray([48, 51, 48, 82, 94, 77, 51])

# scaling the x- axis with 100
x = np.arange(0, len(lowT)) * 100

# create rectangle
arr = np.ones((100, x.max()))
y = np.arange(1, 101).reshape(100, 1)
arr = np.multiply(arr, y)

fig = go.Figure(data = go.Contour(z=arr, colorscale='bluered', 
                                  contours_coloring='heatmap', line_width=0))

fig.add_trace(
    go.Scatter(
        x=x, 
        y=hiT,
        fill='none', 
        mode='lines', 
        marker=dict(color='white'),
        showlegend=False
    )
)
fig.add_trace(
    go.Scatter(
        x=x, 
        y=[y.max()]*len(hiT),
        fill='tonexty',
        fillcolor='white',
        mode='lines', 
        marker=dict(color='white'),
        showlegend=False
    )
)
fig.add_trace(
    go.Scatter(
        x=x, 
        y=lowT, 
        fill='tozeroy', 
        fillcolor='white',
        mode='lines',
        marker=dict(color='white'),
        showlegend=False
    )
)

fig.update_layout(plot_bgcolor="white")

fig.show()

2 Likes