How to define hovertext using add_layout_image

Hello, I have created the following graph using fig.add_layout_image


I want to create hovertext with the team name in case the viewer doesn’t recognize the logo. However fig.add_layout_image doesn’t have hovertext parameters like most of the other plotly graph objects. Is there some other way to add this? I believe I want this more customizable than anything I can load into the layout since it won’t be the plotted values.

Hey @marketemp,

Here’s my idea:

You can add dummy trace with hovertext and set opacity zero to make it invisible.

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(x=[1,20,30],
                         y=[1,25,35],
                         mode="markers")
              )


#Dummy Rectangle -> opacity = 0 (invisible)
fig.add_trace(
        go.Scatter(
            x=[10,10,15,15,10], #x1-x1-x2-x2-x1
            y=[15,20,20,15,15], #y1-y2-y2-y1-y1

            fill="toself",
            mode='lines',
            name='',
            text='Custom text on top of shape',
            opacity=0
        )
    )



## Add image
fig.add_layout_image(
    dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
        xref="x", yref="y", # reference to axis not to paper
        x=10, y=20,         # position
        sizex=5, sizey=5,   # size
    )
)

# update layout properties
fig.update_layout(
    height=800,
    width=800)

fig.show()```
3 Likes

Hello @marketemp

Do you have many images? Why you don’t edit the image and add the title?

2 Likes

Thanks @akroma, your strategy works perfect! Thanks for the great code example.

1 Like

I have about five hundred images and have already spent many hours modifying them from a white background (each look like white squares and block each other out) to a neutral background.

1 Like

Hey @marketemp ,

Glad to help.

Have a nice day.

1 Like

Definitely is no good idea if you have to manually edit many images. I happy to see, that @akroma was able to help you.

2 Likes