Black Lives Matter. Please consider donating to Black Girls Code today.

How to add lines in heatmap?

Is it possible to add line plots to a heatmap? I’m not interested in grid lines but vertical or horizontal lines corresponding to actual data.

@fkromer Yes, you can define two traces, one of type 'heatmap' and another, 'scatter':

N = 25
x = np.linspace(0, 2, N)
y = np.linspace(-1, 1, N)
z = np.random.rand(50, N)

heatmap = go.Heatmap(x=x, y=y, z=z, colorscale='Greens', colorbar_thickness=20)
lines = go.Scatter(x=[0.5, 1.25, None, 1.65, 1.65],
                   y=[-0.67, -0.67, None, -1,1],
                   line_color='black', line_width=2.5)
layout = go.Layout(width=600, height=600, 
                   xaxis_range=[0,2], yaxis_range=[-1,1])
fig = go.Figure(data=[heatmap, lines], layout=layout)

@empet That’s so obvious that I missed to try it :slight_smile: Thx.