I would like to combine interactive builds in Matplotlib and the Cmd command line interface in python. How can i do this? Can I use streams? I tried the following:
from cmd import Cmd
import matplotlib.pylab as plt
from threading import Thread
class MyCmd(Cmd):
def __init__(self):
Cmd.__init__(self)
self.fig = plt.figure()
self.ax = self.fig.add_subplot(1,1,1)
def do_foo(self, arg):
self.ax.plot(range(10))
self.fig.canvas.draw()
if __name__=='__main__':
c = MyCmd()
Thread(target=c.cmdloop).start()
plt.show()
It opens a shape window, and I can enter commands in the actually executed console. When the "foo" command is executed, it draws in the drawing window. So far so good. However, when you enter the console, the console seems to be stuck, and now a new command window has appeared. But when I click on the shape window, the console displays a new command line, and I can enter a new command. It seems that the two loops are not alternating or something like that. Is there a better, more general way?