我有堆积的条形图。我想在条形图中的段上添加数字(y值),而在悬停时希望显示一些其他信息(而不是name或x或y值)。
可能吗?据我hoverinfo所知,您只需要复制文本中的值或添加名称即可。
hoverinfo
import plotly from plotly.graph_objs import Layout, Bar hoverinformation = ["test", "test2", "test3", "test4"] # this info I would like it on hover data = [] for index, item in enumerate(range(1,5)): data.append( Bar( x="da", y=[item], name="Some name", # needs to be different than the hover info text=item, hoverinfo="text", textposition="auto" ) ) layout = Layout( barmode='stack', ) plotly.offline.plot({ "data": data, "layout": layout })
这是一个简单的堆栈栏,悬停时的值可以在pandas数据框中,也可以在变量中 hoverinformation
hoverinformation
最好是一个不涉及在另一个之上创建2个图的解决方案…
是的,您可以使用hovertext元素来执行此操作。文件
hovertext
import plotly.graph_objs as go from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot init_notebook_mode(connected=True) hoverinformation = ["test", "test2", "test3", "test4"] # this info I would like it on hover data = [] for index, item in enumerate(range(1,5)): data.append( go.Bar( x="da", y=[item], hovertext=hoverinformation[index], # needs to be different than the hover info text=[item], hoverinfo="text", name="example {}".format(index), # <- different than text textposition="auto", ) ) layout = go.Layout( barmode='stack', ) iplot({ "data": data, "layout": layout })