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

Help with finding equivalent functions for matplotlib and scipy in plotly

I’m a complete novice at plotly and would really appreciate if someone could point me to equivalents of plotting functions from matplotlib that would result in a plot displayed below. The plot shows heat interpolation between dots (sensors).


from scipy.interpolate.rbf import Rbf #Radial basis functions
from sqlalchemy import create_engine
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

im = plt.imread('C:\\Users\\definitely_not_me\\Downloads\\floor_plan.jpg')

# Create Figure and Axes objects
fig,ax = plt.subplots(1)

# Display the image on the Axes
implot = ax.imshow(im)

# Define location of "sensors" on the axes
x = [100, 100, 100, 250, 250, 250, 400, 400, 400]
y = [100, 350, 600, 100, 350, 600, 100, 350, 600]
z = [22, 23, 22, 22, 25, 15, 21, 22, 22] #temperature

rbf_adj = Rbf(x, y, z, function = 'gaussian')

# Set extent to which colour mesh stretches over
# the underlying image
x_fine = np.linspace(0, 1000, 81) #81 - num of samples
y_fine = np.linspace(0, 700, 82)

x_grid, y_grid = np.meshgrid(x_fine, y_fine)

z_grid = rbf_adj(x_grid.ravel(), y_grid.ravel()).reshape(x_grid.shape)

# plot the pcolor on the Axes. Use alpha to set the transparency
p=ax.pcolor(x_fine, y_fine, z_grid, alpha=0.3)
ax.invert_yaxis() #invert Y axis for X and Y to have same starting point

# Add a colorbar for the pcolor field


I know of these (1 and 2 )tutorials related to background images and interpolation in a 3d space but whenever I try to produce anything of real value I end up with some unintelligible mess. Thanks in advance!

the heatmap tutorial should be of interest to you If your image is single-channel (grayscale) you can plot it using a Heatmap. Otherwise, we have an Image trace and an imshow function which will be shipped with the next version of next week.
You can also use a Heatmap for replacing matplotlib’s pcolor. For the interpolation, you should just keep on using scipy as you’re doing which is great. Otherwise you can make a contour plot from your data points, which will also perform interpolation. See for example