![](/img/trans.png)
[英]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.