Converting matplot image fig to plotly object

I’m running the following code to create a dash plotly app with an image created by matplotlib.
I’m getting the following error message.
“Aw. Snap! You’re gonna have to hold off on the selfies for now. Plotly can’t import images from matplotlib yet!”

Is there a workaround? I can use plotly imshow function, but it takes 10 times longer to create an image. I’m trying to reduce the lag time between the image updates for my interactive app.

This is just a sample code to indicate the problem.

from import mpl_to_plotly
from matplotlib import pyplot as plt
import dash
import dash_html_components as html
import dash_core_components as dcc
from jupyter_dash import JupyterDash
import dash_bootstrap_components as dbc
import numpy as np

app= JupyterDash(name, external_stylesheets=[dbc.themes.LUX], #[dbc.themes.BOOTSTRAP],
meta_tags=[{‘name’: ‘viewport’,
‘content’: ‘width=device-width, initial-scale=1.0’}],

fig= plt.figure()
ax= fig.add_subplot(111)
image = np.random.random([300, 5000])
ax.imshow(image, vmin=0, vmax=1, cmap=“gray_r”, aspect=“auto”)
plotly_fig = mpl_to_plotly(fig)

app.layout= html.Div([
dcc.Graph(id= ‘matplotlib-graph’, figure=plotly_fig)


app.run_server(host=‘’, port=3067, mode=‘external’)


It should be straigthforward to add with html.Iframe. Please take a look on Adam’s video on the topic:

1 Like