首页 > 解决方案 > Plotly(Dash)将鼠标悬停在两点之间的线上并获取值 - python

问题描述

使用 pandas 数据框和 plotly 绘制以下内容:

散点图

使用情节快递:

    fig= px.line(
             df.sort_values(by='allocation'),
             x='allocation',
             y='cost')

    fig.data[0].update(mode='markers+lines',
             line = dict(shape = 'linear', color = 'rgb(10, 12, 240)', dash = 'dash'),
             connectgaps = True,)

当我将鼠标悬停在标记上时,我会得到预期的弹出窗口,其中 x 和 y 值正确命名。将鼠标悬停在由 绘制的线条connectgaps=True上时,有什么方法可以得到相同的结果吗?所以悬停在两点之间的线上会给我创建线的那个点的 x 和 y 值吗?

我希望避免必须创建一个公式并为每个单独的段添加一行(并找出最好的方法!)。

标签: pythonplotlyplotly-dashplotly-python

解决方案


推荐阅读