Direct labels and hover info to be different in plotly

落爺英雄遲暮 提交于 2019-11-29 16:30:56

Yes you can do this by using the hovertext element. Docs

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
})

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!