I am trying to generally recreate this graph and struggling with adding a column to the hovertemplate of a plotly Scatter. Here is a working example:
import pandas as pd
import chart_studio.plotly as py
import plotly.graph_objects as go
dfs = pd.read_html('https://coronavirus.jhu.edu/data/mortality', header=0)
df = dfs[0]
percent = df['Case-Fatality'] # This is my closest guess, but isn't working
fig = go.Figure(data=go.Scatter(x=df['Confirmed'],
y = df['Deaths'],
mode='markers',
hovertext=df['Country'],
hoverlabel=dict(namelength=0),
hovertemplate = '%{hovertext}<br>Confirmed: %{x}<br>Fatalities: %{y}<br>%{percent}',
))
fig.show()
I'd like to get the column Cast-Fatality
to show under {percent}
I've also tried putting in the Scatter()
call a line for text = [df['Case-Fatality']],
and switching {percent}
to {text}
as shown in this example, but this doesn't pull from the dataframe as hoped.
I've tried replotting it as a px
, following this example but it throws the error dictionary changed size during iteration
and I think using go
may be simpler than px
but I'm new to plotly.
Thanks in advance for any insight for how to add a column to the hover.