I have
import pandas as pd
import plotly.express as px
import numpy as np
import seaborn as sns
import matplotlib.colors as mc
import matplotlib as mpl
data = {
‘Continent’: [‘Asia’, ‘Europe’, ‘North America’, ‘Africa’, ‘South America’, ‘Oceania’],
‘Country’: [‘China’, ‘Germany’, ‘USA’, ‘Nigeria’, ‘Brazil’, ‘Australia’],
‘Exports’: [1,2,3,4,5,6],
‘Imports’: [7,8,9,10,11,12],
‘Top export’: [‘Electronics’, ‘Vehicles’, ‘Machinery’, ‘Oil’, ‘Soybeans’, ‘Minerals’],
‘GDP’: [13,14,15,16,17,18,19],
‘Region’: [‘Asia’, ‘Europe’, ‘North America’, ‘Africa’, ‘South America’, ‘Oceania’]
‘Region’: [‘Asia’, ‘Europe’, ‘North America’, ‘Africa’, ‘South America’, ‘Oceania’]
}
df = pd.DataFrame(data)
df = df.dropna().reset_index(drop=True)
fig = px.scatter(
data_frame=df,
x=‘Imports’,
y=‘Exports’,
color=‘Region’,
size=‘GDP’,
)
hovertemplate = (
‘%{customdata[0]}
’
‘GDP: %{customdata[2]}
’
)
fig.update_traces(
# selector=dict(type=‘scatter’),
hovertemplate=hovertemplate,
customdata=df
)
fig.show();
But I can’t seem to find/figure how to access the hover data in order to successfully format it. The code above will label all data points with identical hover data. When i comment out the line ‘hovertemplate=hovertemplate’, the data I would wish to use is available on hover, but I can’t figure out how to access it. Anybody, who can nudge me in the right direction?