我有一个非常基本的绘图,我想添加一个功能,当鼠标悬停在绘图上的数据点上时,可以显示值。
我用来创建折线图的代码如下:
df_all['count'] = pd.to_numeric(df_all['count'])
cumulative = df_all['count'].cumsum()
cumulative.plot()
plt.plot()
print(plt.show())
非常感谢
答案 0 :(得分:1)
在关于Plotly的评论中,这是一个非常简单示例,说明如何绘制具有可徘徊趋势的图表。
示例代码:
import random
import pandas as pd
from plotly.offline import plot
# Create a random list of values.
vals = [random.randint(0, 10) for _ in range(100)]
# Create a test DataFrame.
df = pd.DataFrame({'count': vals})
df['cumsum'] = df['count'].cumsum()
使用Plotly创建图形:
# Plot the results.
traces = []
traces.append({'y': df['count'], 'name': 'Single Counts'})
traces.append({'y': df['cumsum'], 'name': 'Cumulative'})
plot({'data': traces})
输出:
如您所见,我的光标悬停在x:50,y:248。显示的文本是高度可配置的,可以在hovertext documentation中进行查看。
TL; DR:
鉴于Plotly提供的广泛配置功能,很容易在Dash,Plotly Express,Figure Factories等中迷失方向,并得出以下结论:“我真正需要什么解决方案?” -我认为显示一个精简的(至今完全有用的)示例如何绘制具有可徘徊趋势的图表会很有帮助。
答案 1 :(得分:0)
This post在悬停散点图时使用放大器显示数据。可以作为参考。