0

Can anybody offer some information about how to add a plotly image as an object in the legend that I can click to trigger it on or off? Just like how the scatter plot can be triggered on or off, I want the same capability for the image.

import numpy as np
import plotly
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots

imgR = np.random.rand(20, 40)

fig = go.Figure()

fig.add_trace(
    go.Scatter(
        x=[1, 2, 3, 4, 5],
        y=[4, 5, 6, 7, 8],
        mode='markers',
        name='test'
    )
)

fig.add_trace(
    px.imshow(
        imgR,
        color_continuous_scale='gray',
        origin='lower'
    ).data[0]
)

# fig.add_trace(px.imshow(imgR).data[0])

fig.update_layout(
    showlegend=True,
    title="Plot Title",
    xaxis_title="X Axis",
    yaxis_title="Y Axis",
    legend_title="Legend Title",
    legend=dict(
        xanchor='right',
        yanchor='top',
        traceorder="reversed",
        title_font_family="Times New Roman",
        font=dict(
            family="Courier",
            size=12,
            color="black"
        )
    )
)

fig.show()
JON
  • 23
  • 1
  • 5

0 Answers0