Chr*_*ard 7 python plot plotly
我目前正在使用情节服务来绘制一些水质数据.我添加了一些线来代表水质的各个阶段,它们被遮蔽,因此它们是绿色,黄色和红色.
我已经能够从图例中删除一些不必要的线条,但是当它们悬停在数据上时它们仍会显示出来.我看过这里的文字和注释,但在尝试使用"hoverinfo"参数时,我得到了一个
"plotly.exceptions.PlotlyDictKeyError:无效键,'hoverinfo',类,'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"
)
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
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
Run Code Online (Sandbox Code Playgroud)
如果您使用plotly.express
,则可以使用这一行:
fig.update_layout(hovermode=False)
Run Code Online (Sandbox Code Playgroud)
在您的跟踪上添加:hoverinfo ='skip'
trace = dict(
x=[1,2,3,4],
y=[1,2,3,4],
hoverinfo='skip'
)
Run Code Online (Sandbox Code Playgroud)