Embed image as plot background

Hi @merlo and welcome to the plotly community!

When using a local image file, use the Pillow library to read the image.

from PIL import Image

#storing in a variable to pass into the source
img = Image.open("/assets/image.png")

fig = go.Figure(data=[edge_trace, sel_edge_trace, node_trace],
             layout=go.Layout(
                showlegend=False,
                margin=dict(b=20,l=5,r=5,t=40),
                xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
                yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
                )
...
fig.add_layout_image(dict(
                        source=img,
                        xref="x",
                        yref="y",
                        x=50,
                        y=50,
                        xanchor="center",
                        sizex=50,
                        sizey=50,
                        sizing="stretch",
                        opacity=0.5,
                        layer="below"))
1 Like