Plotly的文档显示了一个悬停模板,可以访问文本中的 x 和 y 值,但是我们如何访问其他列中的数据呢?
进口:
import pandas as pd
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
代码:
test_data = {"client1-percent":[90,100,60]
, "client1-volume":[500000,3542,20000]
, "client2-percent":[99,63,98]
,"client2-volume":[6423,6524,5737]
}
df = pd.DataFrame(test_data)
data = [go.Scatter(
x = df.index.values
, y = df.loc[:,col].values
, hovertemplate = "Percent: %{y:.1f}% | Volume: {}"
, mode = 'lines+markers'
, name = col.replace("-percent","")
) for col in df.columns if "-volume" not in col]
plot(data, filename='test.html')
所以这里的具体问题是:如何将客户端音量添加到这个绘图工具提示中的文本中?