默认情况下禁用跟踪上的悬停信息

时间:2015-08-31 20:39:37

标签: python plot plotly

我目前正在使用情节服务来绘制一些水质数据。我添加了一些线来代表水质的各个阶段,它们被遮蔽,因此它们是绿色,黄色和红色。

我已经能够从图例中删除一些不必要的行,但是当将鼠标悬停在数据上时它们仍会显示。我看过这里text and annotations,但在尝试使用“hoverinfo”参数时,我得到了一个

  

“plotly.exceptions.PlotlyDictKeyError:无效键,'hoverinfo',用于   class,'Scatter'。“

错误。是否有另一种方法可以为Scatter绘图执行此操作?到目前为止,我看起来并没有发现任何有用的东西。

以下是我目前正在尝试设置跟踪的方法:

badNTULevel = Scatter(                                                                              
x=[],                                                                                           
y=[100],                                                                                        
mode='lines',                                                                                   
line=Line(                                                                                      
    opacity=0.5,                                                                                
    color='rgb(253,172,79)',                                                                    
    width=1,                                                                                    
),                                                                                              
stream=Stream(                                                                                  
    token=stream_ids[3],                                                                        
    maxpoints=80                                                                                
),                                                                                              
hoverinfo='none',                                                                               
fill='tonexty',                                                                                 
name="Water Treatment Plants Can't Process over 100"
)                                        

任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:2)

from plotly.offline import plot
import plotly.graph_objs as go

def spline(x_axis,loop):

     trace = go.Scatter(
        x = x_axis,
        y = loop[i],
        fill = 'tonexty',
        mode ='lines',
        showlegend = False,
        hoverinfo='none'
        )

    data = [trace]



    layout = go.Layout(
        title='Graph title here',
        height=600,
        xaxis=dict(
            autorange=True
        ),
        yaxis=dict(
            autorange=True
        )
    )
    fig = go.Figure(data=data, layout=layout)
    # plot(fig, filename='spline.html')
    plot_div = plot(fig, output_type='div', include_plotlyjs=False)
    return plot_div

答案 1 :(得分:2)

在跟踪中添加: hoverinfo ='skip'

trace = dict(
             x=[1,2,3,4],
             y=[1,2,3,4],
             hoverinfo='skip'
            )

答案 2 :(得分:0)

更通用的解决方案可能是设置Layout'hovermode'属性,如下所示:

#...
layout = go.Layout(hovermode=False)
fig = go.Figure(data=data, layout=layout)
#...

此处提供Python参考:https://plot.ly/python/reference/#layout

注意:这将禁用与该布局相关的所有迹线的悬停文本...可能不是您想要的行为。

相关问题