8

I want to dynamically update the scatter plot based on the y-axis data received from a socket connection. I used python matplot lib in interactive mode to do this, but during dynamic updation if i move the window to a different location or minimize the window then the plot updation stops abruptly. How to do this?

I have attached a sample dynamic updation code used here and the same problem appears here also.

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()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sharath
  • 81
  • 1
  • 1
  • 2

2 Answers2

4

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

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
2

For this to work, you need to have a main loop for event handling, and your own event handler to redraw the plot when the window is resized or refreshed.

You'll find many examples for this on the web, or in the tutorials.

I think this is best handled by using a UI toolkit (e.g. wxPython), not using matplotlib interactive mode. I had a similar question in the past and got some good answers.

Community
  • 1
  • 1
Ber
  • 40,356
  • 16
  • 72
  • 88
  • Thanks for the answer, I searched for event handling examples but could not find it(I am newbie to python), can you please send me link to at least one such example. – Sharath Dec 22 '09 at 09:52
  • @Sharath: You'll find links in the answer I linked to. – Ber Dec 22 '09 at 10:55
  • @Ber: I meant event handling in matplot examples and not wxPython, like what are the events i get for window minimize, movement to a different location,etc. Thanks in advance – Sharath Dec 22 '09 at 12:59
  • @Sharait: Sorry, but I can't help you there, I only use matplotlib with wxPython, not on its own. – Ber Dec 22 '09 at 14:23