gpt4 book ai didi

python - 无法在 python 3.5 中动态更新 pyplot

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:16 26 4
gpt4 key购买 nike

想要使用以下代码来动态演示预测 (<<2) 如何接近真实值 (<<1)。然而,只有<<1出现,完全看不到<<2出现。有办法解决吗?

.....
# plot the real data
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.scatter(x_data, y_data) <<<< 1
plt.ion()
plt.show()

for i in range(1001):
sess.run(train_step, feed_dict={xs:x_data, ys:y_data})
if i % 50 == 0:
print(sess.run(loss,feed_dict={xs:x_data, ys:y_data}))
try:
ax.lines.remove(lines[0])
except Exception: # if plotting the first time
pass
prediction_value = sess.run(prediction, feed_dict={xs:x_data})
lines = ax.plot(x_data,prediction_value,'r-', lw = 5) <<< 2
plt.pause(0.1)

提前致谢!

最佳答案

plt.show() 等待您关闭绘图窗口,然后再继续。如果您删除它,但仍然保留 plt.ion() 并且您的平台支持它,它应该可以正常运行:

plt.ion()
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(0, 0, 'o')

for i in range(1,10):
ax.plot(i, i, 'o')
plt.pause(1)

适用于 Mac 上的 matplotlib 2.0.0、Python 3.5(每秒绘制一个点)

关于python - 无法在 python 3.5 中动态更新 pyplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com