On Fri, Jul 2, 2010 at 6:20 AM, ninjasmith <henrylindsaysm...@gmail.com> wrote:
> ok made some prgoress with this so thought I'd update
>
> the following script works on widnows
>
> '''
> Created on Jul 1, 2010
>
> @author: henrylindsaysmith
> '''
> # $Id: $
>
> #test interactive matplotlib plotting
>
> import threading
> import numpy as np
> import sys
> import matplotlib
> matplotlib.use('TkAgg')
> import matplotlib.pylab as pyp
>
>
> class MyThread(threading.Thread):
>
>    def __init__ (self, data, label):
>        self.data  = data
>        self.label = label
>        threading.Thread.__init__ ( self )
>
>    def run(self):
>        pyp.plot(self.data)
>        pyp.xlabel('%s' % self.label)
>        pyp.show()
>
> a = np.array([0, 4, 5, 5, 3, 4, 5])
> MyThread(a,'first x label').start()
> print ("please input x label")
> input = sys.stdin.readline()
> MyThread(a,input).start()
>
>
> so basically abandoning interactive mode and running in a thread works.  the
> first show shows the plot which I can then interact with.  After I input
> from the keyboard the second plot updates the figure.
>
> BUT
>
> on mac I get the following errors
>
> 1) the figure window appears but has no content
> 2) after the keyboard input the xlabel updates and the figure content
> displays and I get the following error
>
> Exception in thread Thread-2:
> Traceback (most recent call last):
>  File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py",
> line 525, in __bootstrap_inner
>    self.run()
>  File "threadedMatplotLIb.py", line 28, in run
>    pyp.show()
>  File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backends/backend_tkagg.py",
> line 79, in show
>   Tk.mainloop()
>  File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py",
> line 325, in mainloop
>    _default_root.tk.mainloop(n)
> RuntimeError: Calling Tcl from different appartment
>
> I tried the backend macosx and the results were worse!!  I'd rather use mac
> if I can due to scikits.audiolab not installing in windows.
>
> anyone shed any lights on the thread problem?

A lot of GUI toolkits don't permit multi-threaded access to their
event loops. What you really want is to integrate your interaction
into that loop itself, so that the GUI handles things for you. Try
looking at the examples here:

http://matplotlib.sourceforge.net/examples/event_handling/

Specifically:

http://matplotlib.sourceforge.net/examples/event_handling/keypress_demo.html

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to