[英]How animation scatter plot with Matplotlib can be done with not superimposed data?
[英]matplotlib smooth animation superimposed on scatter plot
以下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
///
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.