Description
Hi Plotly team!
It is not currently possible to add an image to a FigureWidget
. I suspect this is tied to the FigureWidget
upgrade in PR #4823, where anywidget
is swapped in for ipywidgets
. Consider the examples below:
Example 1 (successful addition of image to FigureWidget
):
plotly v5.24.1 (before anywidget use)
anywidget not installed
notebook v7.3.1 (classic notebook)
import plotly.graph_objects as go
# Create a Plotly figure
fig = go.FigureWidget()
# Add an image to the figure
fig.add_layout_image(
dict(
source="https://images.plot.ly/language-icons/api-home/python-logo.png",
xref="x"
yref="y"
x=1,
y=1,
sizex=1,
sizey=1,
xanchor="center",
yanchor="middle"
)
)
fig
Example 2 (unsuccessful addition of image to FigureWidget
):
plotly v6.0.0rc0 (after anywidget use)
anywidget v0.9.13
notebook v7.3.1 (classic notebook)
import plotly.graph_objects as go
# Create a Plotly figure
fig = go.FigureWidget()
# Add an image to the figure
fig.add_layout_image(
dict(
source="https://images.plot.ly/language-icons/api-home/python-logo.png",
xref="x"
yref="y"
x=1,
y=1,
sizex=1,
sizey=1,
xanchor="center",
yanchor="middle"
)
)
fig
Any ideas on the reason behind this issue?
Note that, in both cases, the image is successfully added when just a Figure
(not a FigureWidget
) is used, so it doesn't seem to be an issue with the Figure
class. And while in both cases runningfig.layout.images
produces a dictionary consistent with the addition of an image, that dictionary is empty in the second example.