更新 python\\’s matplotlib 中的绘图 | 珊瑚贝

Updating a plot in python’s matplotlib


我正在尝试在 matplotlib 中绘制流数据。我可以使用交互模式和 set_ydata 函数更新绘图。它动画并且一切看起来都很好,直到循环结束。然后 python 内核崩溃,我收到以下消息:

C:\\Conda\\lib\\site-packages\\matplotlib\\backend_bases.py:2437:
MatplotlibDeprecationWarning: Using default event loop until function specific to
this GUI is implemented
warnings.warn(str, mplDeprecation)

这是代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 10, 0.1)
y = np.sin(x)

plt.ion() #interactive mode on
ax = plt.gca()
line, = ax.plot(x,y)
ax.set_ylim([5,5])

for i in np.arange(100):
    line.set_ydata(y)
    plt.draw()
    y = y*1.01
    plt.pause(0.1)

谁能告诉我为什么会崩溃而不是退出循环?我正在使用 Python 3 在 Jupyter 中执行此操作。当然,如果有更好的方法来执行此操作,我很想听听。谢谢!

这段代码改编自 How to update a plot in matplotlib?


python 3.4 中的 Jupyter 笔记本中的 mac_osx backend 对我来说效果很好。

也许您想在末尾添加 plt.close() 以保持整洁并防止挂断?

  • 嘿,谢谢你的回复!所以,进步… plt.close() 防止内核崩溃。我仍然收到警告。在 python 3.5 和 2.7 的命令行中也会发生同样的事情。两者都使用 matplotlib 1.5.1。我可以忍受这个警告,因为你解决了主要问题,我会接受回复。
  • 很高兴我能帮上忙。也许您想查找 matplotlib 后端并尝试另一个?也许pyqt?看看那个警告是怎么回事……


来源:https://www.codenong.com/36863607/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9190.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?