Daniel Turon
Daniel Turon

Reputation: 21

Overlay Heatmap onto a contour map of different sizes

I want to overlay a heatmap onto a contour plot on plotly with python. The two images come from numpy arrays, and they are different sizes. I will need to overlay the second image at a particular spot on the contour plot, as well I will have to enlarge the plots so that 1 pixel in the heat map corresponds to 1.3 pixels in the contour plot. How can this be done?

I want to produce something like I created here in matplotlib Sample Image edit Here is my current progress Current image

Upvotes: 1

Views: 818

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31166

  • without sample data / generator functions it's not possible to fully answer your question
  • below shows how to layer a heatmap over a contour trace
import numpy as np
import plotly.express as px
import plotly.graph_objects as go

def f(x, y):
    return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)

x = np.linspace(0, 5, 50)
y = np.linspace(0, 5, 40)

X, Y = np.meshgrid(x, y)
Z = f(X, Y)

fig = go.Figure(data=
    go.Contour(
        z=f(X,Y),
        contours_coloring='lines',
        line_width=2,
        coloraxis="coloraxis2"
    )
)

fig.add_traces(px.imshow(Z[:][:]).data).update_layout(coloraxis_showscale=False)

enter image description here

Upvotes: 0

Related Questions