【发布时间】:2020-11-10 10:20:20
【问题描述】:
作为显示线性回归模型拟合进展的一部分,我需要能够更新/刷新 xy 图。下面是 3 组 y 数据的简单脚本,需要按顺序显示。但是,它们是堆叠在一起的。当 fig.canvas.flush_events() 被 fig.clear() 或 fig.clf() 替换时,结果是一个空白图。我 - 作为一个新手 - 缺少什么?
import torch as tc
import matplotlib.pyplot as plt
tc.manual_seed(1)
X=tc.linspace(-3,3,30)
y0=X.pow(2)+0.5*tc.randn(X.shape[0])
y1=y0/1.3
y2=y0/1.6
y=[y0,y1,y2]
fig=plt.figure()
ax=fig.add_subplot()
ax.set_xlim(-3.3,3.3)
ax.set_ylim(-0.5,9.5)
for i in range(3):
y_new=y[i]
ax.plot(X,y_new,'db')
fig.canvas.draw()
fig.canvas.flush_events()
plt.pause(1)
fig.show()
【问题讨论】:
标签: matplotlib linear-regression real-time