0

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?

Community
  • 1
  • 1
Noise in the street
  • 589
  • 1
  • 6
  • 20

1 Answers1

0

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?

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • Hey, thanks for your response! So, progress... `plt.close()` prevented the kernel from crashing. I'm still getting the warning though. The same thing happens from the command line with both python 3.5 and 2.7. Both are using matplotlib 1.5.1. I can live with the warning and I'll accept the response since you solved the main problem. – Noise in the street Apr 26 '16 at 11:42
  • Glad I could help. Maybe you want to look up matplotlib back ends and try another one? maybe pyqt? to see how that warning goes... – Reblochon Masque Apr 26 '16 at 11:46