Merging two arrays on a plot with different transparency and color bar

Iā€™m struggling to come up with a solution using Plotly to reproduce the following code which uses matplotlib.

import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(10, 5), dpi=100)
image = np.random.random([300, 5000])
image2 = np.ones([300, 5000])
plt.imshow(image, vmin=0, vmax=1, cmap="gray_r", aspect="auto", alpha=0.5)
plt.imshow(image2, vmin=0, vmax=1, cmap="seismic", aspect="auto", alpha=0.5)

My goal is to merge two arrays together using transparency parameters for each array. One array is displayed in grey color, another in red color (or seismic). Plotly imshow does not have alpha parameter, so Iā€™m a bit confused about how to implement this simple code using plotly. I need this for my dash plotly app.

it seems, that you want to plot a heatmap. If so, you could do something like this:

import plotly.graph_objects as go
import numpy as np

# create arrays
image_1 = np.random.random([30, 500])
image_2 = np.ones([30, 500])

# create plotly heatmap
trace_1 = go.Heatmap(z=image_1, colorscale='gray_r', opacity=0.4)
trace_2 = go.Heatmap(z=image_2, colorscale='RdBu', opacity=0.2)

# create figure
fig = go.Figure(data=[trace_1, trace_2])

#show figure

The opacity parameter is what you where looking for, I guess.

1 Like