Reputation: 21
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
Upvotes: 1
Views: 818
Reputation: 31166
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)
Upvotes: 0