As I am working on an interactive interface with dash
, I am using plotly
for my figures. However, I have limited experience with the package - I commonly use matplotlib
to make figures.
Anyhow, I want to create a figure using 3D data, where the third dimension is expressed by means of colour. With matplotlib
, I would use pcolormesh
(or pcolor
). Unfortunately, I cannot find an equivalent function within plotly
. I cannot use Contour
or alike, as the z
-data should follow specific (x
,y
)-coordinates.
Let me clarify with an example. For convenience, we can use the following dummy data:
import numpy as np
x, y = np.meshgrid(np.linspace(0, 10), np.linspace(0, 10))
y += 2 * np.sin(x * 2 * np.pi / 10)
z = np.exp(-x / 10)
What I want - and am able to produce using matplotlib
- results from the following code (with the result after it):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.pcolormesh(x, y, z)
However, with plotly
, I do not get any further than using a colour-coded scatter
-plot:
fig = go.Figure()
fig.add_trace(
go.Scatter(x=x, y=y, marker=dict(color=z))
)
This would look something like the following:
This is, however, not what I am aiming for. Enlarging the size of the marker
s to 'trick' the viewer would not suffice, as the actual data is slightly more complex with varying gaps between the (x
,y
)-coordinates.
Hopefully, anyone can help me out. Thanks a lot for your effort!
PS. I have seen this post with a similar question. However, its solution does not apply to me.