python matlabplot animate 刷新,在python的matplotlib中更新图

I'm trying to plot streaming data in matplotlib. I can update the plot using interactive mode and the set_ydata function. It animates and everything looks good until the loop ends. Then the python kernel crashes and I get this message:

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)

Here's the code:

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)

Can anyone tell me why this is crashing instead of just exiting the loop? I'm doing this in Jupyter with Python 3. And of course, if there's a better way to do this, I would love to hear about it. Thanks!

解决方案

It works well for me with mac_osx backend from Jupyter notebook in python 3.4.

Maybe you want to add plt.close() at the end to keep things tidy and prevent a hang up?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值