【发布时间】:2020-07-09 23:17:43
【问题描述】:
我一般都在尝试recreate this 图表,并努力在情节分散的悬停模板中添加一列。这是一个工作示例:
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()
我想让Cast-Fatality 列显示在{percent} 下
我还尝试在Scatter() 中为text = [df['Case-Fatality']], 调用一行并将{percent} 切换为{text},如this example 中所示,但这并没有像希望的那样从数据帧中提取。
我尝试将其重新绘制为px,跟随this example,但它会引发错误dictionary changed size during iteration,我认为使用go 可能比px 更简单,但我是plotly 的新手。
提前感谢您提供有关如何向悬停添加列的任何见解。
【问题讨论】:
-
如果您收到的建议有用,请考虑点赞和/或将其标记为已接受的答案!
-
我愿意,但我要等一天才能接受我的有效答案。
-
帮助您构建自己的解决方案的答案的投票按钮仍然有效,对吧?