Jupyter中的以下Python代码显示了一个显示一些生成的散点图数据的示例,它叠加了一条可以交互式更改y截距和斜率的线,它还显示均方根误差。我的问题是:如何让它更具响应性?有一个滞后和积累的变化被处理,它会闪烁很多。它可以更快,更灵敏,更顺畅吗?
///
%matplotlib inline
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
# Desired mean values of generated sample.
N = 50
# Desired mean values of generated sample.
mean = np.array([0, 0])
# Desired covariance matrix of generated sample.
cov = np.array([
[ 10, 8],
[ 8, 10]
])
# Generate random data.
data = np.random.multivariate_normal(mean, cov, size=N)
xdata = data[:, 0]
ydata = data[:, 1]
# Plot linear regression line
def f(m, b):
plt.figure()
x = np.linspace(-10, 10, num=100)
plt.plot(xdata, ydata, 'ro')
plt.plot(x, m * x + b)
plt.ylim(-10, 10)
rmes = np.sqrt(np.mean(((xdata*m+b)-ydata)**2))
print("Root Mean Square Error: ", rmes)
interactive_plot = interactive(f, m=(-10.0, 10.0), b=(-10, 10, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
///
答案 0 :(得分:0)
您需要在功能结束时使用plt.show()
。有一个JMeter Variables
尝试将FloatSlider
与continuous_update=False
一起使用。 How to Cut Your JMeter Scripting Time by 80%
interactive_plot = interactive(f, m=FloatSlider(min=-10.0, max=10.0, continuous_update=False),
b=FloatSlider(min=-10, max=10, step=.5, continuous_update=False))