1
"""Test the new %gui command. Run this in ipython as
5
In [2]: %run switchgui [backend]
7
where the optional backend can be one of: qt4, gtk, tk, wx.
9
Because of subtle difference in how Matplotlib handles the different GUI
10
toolkits (in things like draw and show), minor modifications to this script
11
have to be made for Tk to get it to work with the 0.99 and below releases
12
of Matplotlib. However, in the future, Matplotlib should be able to have
13
similar logic for all the toolkits, as they are all now using PyOS_InputHook.
19
from IPython.lib import inputhook
21
gui = inputhook.current_gui()
24
inputhook.enable_qt4(app=True)
26
backends = dict(wx='wxagg', qt4='qt4agg', gtk='gtkagg', tk='tkagg')
29
matplotlib.use(backends[gui])
30
matplotlib.interactive(True)
33
from matplotlib import pyplot as plt, mlab, pylab
37
from matplotlib.pyplot import *
39
x = np.linspace(0,pi,500)
41
print "A plot has been created"
42
line, = plot(x,sin(2*x))
43
inputhook.spin() # This has to be removed for Tk
46
print "Now, we will update the plot..."
51
line.set_data(x,sin(x*i))
54
inputhook.spin() # This has to be removed for Tk