1

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

1 Answers1

0
  • 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

Rob Raymond
  • 29,118
  • 3
  • 14
  • 30
  • Thanks this was helpful to start with, I'll add some more info and maybe you can help more if you don't mind, the data arrays are pretty big, so I'll attach an image and just state their sizes. The heatmap is 120x120, the contour is ~400x550. I need the center of the heatmap to overlap the center of the contour plot. As well I need the heatmap to enlarge by some ratio, for the sake of your help lets say 1.5x. For context in case my explanation isn't clear, these are two images from different telescopes for the same galaxy, in radio and optical bands, and I'm wanting to overlay the images. – Daniel Turon Jan 03 '22 at 20:18
  • I will update my original post to show my current figure. – Daniel Turon Jan 03 '22 at 20:18
  • with matplotlib, this is done using extent, is there an extent equivalent for plotly? – Daniel Turon Jan 03 '22 at 20:42