Python Annotation Image Example

Hi can anyone help me to make the tooltip style that shows the small image in plotly python web
Would it be possible to show it only while hovering the point?
Thanks!
image

Hi @casasvil here some information on how to format the hover text

1 Like

yep, but this example looks more complex than the examples

True. If you need support, I suggest providing a MRE

what is an MRE?

1 Like

oh well, no just wondering if exactly that code sample was available, i love the style and just want to copy it :slight_smile:

Hello @casasvil I just made you a sample that gets you pretty close to the supplied screenshot:

from dash import Dash, html, dcc
import plotly.graph_objects as go
import pandas as pd

d = {'Year': [2022,2023], 'Month': ['January','June'], 'A': [1.326, 2.156], 'B': [3.336, 4.625]}
df = pd.DataFrame(data=d)
fig = go.Figure()

fig.add_trace(
    go.Scatter(
        x=df['A'],
        y=df['B'],
        text=df['Month'],
        customdata=df['Year'],
        hovertemplate=
        " Series Identification <br>" +
        "   <b>Year</b>  %{customdata} <br>" +
        " Point Identification <br>" +
        "   <b>Month</b>  %{text} <br>"
        "  Point Values <br>" +
        "     <b>A</b>: %{x} <br>" +
        "     <b>B</b>: %{y} " +
        "<extra></extra>",
    )
)

fig.update_traces(mode='markers')


fig.update_layout(
    hoverlabel=dict(
        bordercolor='pink',
        font_color='black', 
        bgcolor='white') 
)


app = Dash(__name__)

app.layout = html.Div(dcc.Graph(figure=fig))

if __name__ == "__main__":
    app.run_server(debug=True)

I’m not finding a way to center the text inside the hover so I just tossed some spaces in to emulate it. You can remove them if you don’t care about the centering. If you keep the spaces it may not look proper depending on what type of data you’re displaying and the page layout.

Capture

2 Likes

beautiful, thank you!