Direct labels and hover info to be different in plotly

前端 未结 1 1192
刺人心
刺人心 2020-12-22 04:38

I have a stacked bar chart. On the segments in the bar chart I want to add the numbers (y values) and on hover I want some different information to be shown (not name or x o

相关标签:
1条回答
  • 2020-12-22 05:02

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

    0 讨论(0)
提交回复
热议问题