Interactive mode in matplotlib

I want to dynamically update a scatter plot based on y axis data received from a socket connection. I used python matplot lib in interactive mode for this, but during dynamic updating, if I moved the window to another location or hide the window, the plot update will abruptly stop. How to do it?

I applied the dynamic update code example here, and the same problem also appears here.

import matplotlib.pyplot as plt import random import time items = [25.5,26.7,23.4,22.5,20,13.4,15.6,-12,-16,20] x = [1,2,3,4,5,6,7,8,9,10] plt.ion() # Interactive on for i in range(1,100): plt.title('graph plotting') plt.ylabel('temperature') plt.xlabel('time') random.shuffle(items) plt.plot(x,items,'ob-') plt.axis([0, 10, -40, 40]) plt.draw() #time.sleep(2) plt.clf() plt.close() 
+7
python matplotlib
source share
2 answers

This page contains a couple of dynamic chart examples with matplotlib and wxPython. And here is the version with PyQt.

+3
source share

To do this, you need to have a main event processing loop and your own event handler to redraw the chart when changing or updating a window.

You will find many examples for this on the Internet or in textbooks.

I think this is best used with user interface tools (e.g. wxPython ), without using matplotlib interactive mode. I had a similar question in the past and got good answers.

+1
source share

All Articles