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!
This code was adapted from How to update a plot in matplotlib?