禁用跟踪悬停信息,plotly

问题描述 投票:6回答:3

我目前使用的plotly服务图的一些水质数据。我已经添加了一些线条来表示水质的各个阶段,与他们的阴影,使他们有绿色,黄色和红色。

我已经能够去除从图例一些不必要的线条,但是它们仍然显示悬停在数据时。我在这里text and annotations看了,但试图用“hoverinfo”参数时,我得到一个

“plotly.exceptions.PlotlyDictKeyError:无效的关键, 'hoverinfo',上课, '散'。”

错误。是否有这样做的散点图的另一种方式?到目前为止,我看了一下,没有发现任何太大的帮助。

下面是我当前如何试图建立跟踪:

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

任何帮助,将不胜感激。

python plot plotly
3个回答
5
投票

在您的跟踪加:hoverinfo =“跳过”

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

3
投票
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

0
投票

一个更通用的解决方案可以是设置布局“hovermode”属性,如下所示:

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

参考Python的位置:https://plot.ly/python/reference/#layout

注:此为与布局相关联的所有痕迹将禁用悬停文字...可能不是期望的行为。

© www.soinside.com 2019 - 2024. All rights reserved.