如何从绘制生成的HTML图表中删除点并使拟合线动态调整?我不想更改代码中的数据。我还想更新该线的等式。这是代码:
import plotly.plotly as py
import plotly.graph_objs as go
import plotly
# Scientific libraries
from numpy import arange,array,ones
from scipy import stats
# (Almost) linear sequence
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]
# Generated linear fit
slope, intercept, r_value, p_value, std_err = stats.linregress(xi,y)
line = slope*xi+intercept
# Creating the dataset, and generating the plot
trace1 = go.Scatter(
x=xi,
y=y,
mode='markers',
marker=go.Marker(color='rgb(255, 127, 14)'),
name='Data'
)
trace2 = go.Scatter(
x=xi,
y=line,
mode='lines',
marker=go.Marker(color='rgb(255, 127, 14)'),
name='y = %fx + %f' % (slope, intercept)
)
layout = go.Layout(
title='Linear Fit in Python',
)
data = [trace1, trace2]
fig = go.Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename='Linear-Fit-in-python')