|
From: ninjasmith <hen...@gm...> - 2010-07-02 11:21:01
|
> ipython does this, I believe, when you call it with the -pylab option, but
I have never tried it with a script.
Ben Root
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?
--
View this message in context: http://old.nabble.com/matplotlib-in-interactive-mode-from-a-script-tp29023641p29055179.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|