Hi @emmanuelkatto,
Here is an example of customized hover info, used for plotting major league base ball wins & losses of National League West teams. If you have any questions or care to post a code sample I can help you with this task. Hover if one of my favorite features of plotly, so I do this frequently.
# Custom Hover Example - August 28, 2024
# MLB National League West baseball standings
import pandas as pd
import plotly.express as px
import numpy as np
df = pd.DataFrame(
{
'TEAM' : ['Dodgers', 'Diamondback', 'Padres', 'Giants', 'Rockies'],
'LOCATION' : ['Los Angeles', 'Arizona', 'San Diego', 'San Francisco', 'Colorado'],
'WINS' : [78, 75, 76, 67, 49],
'LOSSES' : [54, 57, 58, 66, 84],
'MANAGER' : ['Roberts','Lovullo','Shildt','Melvin','Black'],
'DES. HITTER' : ['Ohtani','Pederson','Cruz','Rodriguez','Blackmon'],
'TOP PITCHER' : ['Yamamoto','Gallen','Musgrove','Webb','Quantrill']
}
)
df['GAMES'] = df['WINS'] + df['LOSSES']
df['PCT'] = df['WINS'] / df['GAMES']
df['PCT'] = df['PCT'].apply(lambda x: round(x, 3))
fig = px.scatter(
df,
'LOSSES',
'WINS',
)
fig.update_layout(
template = 'plotly_white',
width=500,
height=300,
title='MLB National League West, August 28, 2024'
)
customdata = np.stack(
[
df['LOCATION'], # customdata[0]
df['TEAM'], # customdata[1]
df['WINS'], # customdata[2]
df['LOSSES'], # customdata[3]
df['PCT'], # customdata[4]
df['MANAGER'], # customdata[5]
df['DES. HITTER'], # customdata[6]
df['TOP PITCHER'] # customdata[7]
],
axis=-1
)
hovertemplate = (
'<b>%{customdata[0]} %{customdata[1]}</b> (%{customdata[2]} - %{customdata[3]}) %{customdata[4]:.3f} PCT<br>' +
'<b>Manager:</b> %{customdata[5]} <br>' +
'<b>Designated Hitter:</b> %{customdata[6]} <br>' +
'<b>Top Pitcher:</b> %{customdata[7]} <br>' +
'<extra></extra>')
fig.update_traces(customdata=customdata, hovertemplate=hovertemplate)
print(df.to_string(index=False))
fig.write_html('MLB_WEST.html')
fig.show()