我正在使用袖扣来绘制熊猫数据框。如何在悬停模板中包含恍惚名称(列名)?
我使用 name=df.columns.to_list() 然后在 hovertemplate 中使用 %{name} 并且它不起作用。感谢帮助。
fig=df.iplot(xTitle='Time',yTitle='Temperature(degC)',title=title,name=df.columns.to_list(),
size=10,width=4,asFigure=True)
fig.update_traces(hovertemplate='Location: %{name}<br>'+'Date: %{x|%b %d %H:%M,%Y} ,<br>Value:%{y}')
df.head().to_dict()
{499.95: {Timestamp('2021-10-30 21:08:00'): 224.09,
Timestamp('2021-10-30 21:17:00'): 224.78,
Timestamp('2021-10-30 21:27:00'): 223.12,
Timestamp('2021-10-30 21:36:00'): 224.3,
Timestamp('2021-10-30 21:45:00'): 225.06},
627.62: {Timestamp('2021-10-30 21:08:00'): 229.74,
Timestamp('2021-10-30 21:17:00'): 230.66,
Timestamp('2021-10-30 21:27:00'): 228.76,
Timestamp('2021-10-30 21:36:00'): 230.0,
Timestamp('2021-10-30 21:45:00'): 230.32},
755.29: {Timestamp('2021-10-30 21:08:00'): 230.42,
Timestamp('2021-10-30 21:17:00'): 231.13,
Timestamp('2021-10-30 21:27:00'): 229.0,
Timestamp('2021-10-30 21:36:00'): 230.28,
Timestamp('2021-10-30 21:45:00'): 231.21},
882.96: {Timestamp('2021-10-30 21:08:00'): 188.76,
Timestamp('2021-10-30 21:17:00'): 190.16,
Timestamp('2021-10-30 21:27:00'): 189.01,
Timestamp('2021-10-30 21:36:00'): 191.25,
Timestamp('2021-10-30 21:45:00'): 191.52},
1010.63: {Timestamp('2021-10-30 21:08:00'): 196.5,
Timestamp('2021-10-30 21:17:00'): 197.54,
Timestamp('2021-10-30 21:27:00'): 196.08,
Timestamp('2021-10-30 21:36:00'): 198.45,
Timestamp('2021-10-30 21:45:00'): 198.66},
1138.3: {Timestamp('2021-10-30 21:08:00'): 206.63,
Timestamp('2021-10-30 21:17:00'): 206.79,
Timestamp('2021-10-30 21:27:00'): 205.9,
Timestamp('2021-10-30 21:36:00'): 207.4,
Timestamp('2021-10-30 21:45:00'): 208.54},
1265.97: {Timestamp('2021-10-30 21:08:00'): 213.16,
Timestamp('2021-10-30 21:17:00'): 214.1,
Timestamp('2021-10-30 21:27:00'): 212.56,
Timestamp('2021-10-30 21:36:00'): 214.97,
Timestamp('2021-10-30 21:45:00'): 215.12},
1393.64: {Timestamp('2021-10-30 21:08:00'): 202.74,
Timestamp('2021-10-30 21:17:00'): 205.55,
Timestamp('2021-10-30 21:27:00'): 203.71,
Timestamp('2021-10-30 21:36:00'): 207.18,
Timestamp('2021-10-30 21:45:00'): 203.78},
1521.31: {Timestamp('2021-10-30 21:08:00'): 199.74,
Timestamp('2021-10-30 21:17:00'): 200.83,
Timestamp('2021-10-30 21:27:00'): 199.52,
Timestamp('2021-10-30 21:36:00'): 201.96,
Timestamp('2021-10-30 21:45:00'): 203.11},
1648.98: {Timestamp('2021-10-30 21:08:00'): 127.69,
Timestamp('2021-10-30 21:17:00'): 127.94,
Timestamp('2021-10-30 21:27:00'): 127.1,
Timestamp('2021-10-30 21:36:00'): 128.06,
Timestamp('2021-10-30 21:45:00'): 128.75}}