简体   繁体   English

当我将Plotly Interactive Graph悬停在折线图中的特定点上时,如何更改显示的内容

[英]How can I change what my Plotly Interactive Graph displays when it hovers over a specific point in the line graph

The title explains it all. 标题说明了一切。 Currently it just displays the X and Y values of that specific point but I would like it to display some text that is associated with that point. 当前,它仅显示该特定点的X和Y值,但是我希望它显示与该点相关的一些文本。 Is there a way to manually override what is displayed in these interactive plots? 有没有办法手动覆盖这些交互式绘图中显示的内容?

fig = plt.figure(figsize=(15,7))
plt.plot(X1,Y1, label = 'One')
plt.plot(X2,Y2, label = 'Two')
plt.ylim([-1.0,1.0])
leg = plt.legend(loc='lower right',
       ncol=3,
       fontsize=15,
        fancybox=True)
leg.get_frame().set_facecolor('white')
leg.get_frame().set_edgecolor('grey')
plt.show()

py.iplot_mpl(fig)

I'm just converting a simple Matplotlib code to a plotly plot. 我只是将一个简单的Matplotlib代码转换为一个绘图。 Any advice will be much appreciated. 任何建议将不胜感激。

-MT -公吨

Just add the text attribute to your trace to control the text which is shown when you hover over the data point. 只需将text属性添加到trace即可控制将鼠标悬停在数据点上时显示的文本。

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Scatter(
    x=[1, 2, 3],
    y=[1, 2, 3],
    text=['One', 'Two', 'Three'],
    mode='markers'
)

data = go.Data([trace0])
plot_url = py.plot(data)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM