Skip to content

Adding image fails with revamped FigureWidget #4932

Closed
@robertcollar-kobold

Description

@robertcollar-kobold

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

Image

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

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions