Show More
@@ -1,48 +1,54 b'' | |||||
1 | """Test the new %gui command. Run this in ipython as |
|
1 | """Test the new %gui command. Run this in ipython as | |
2 |
|
2 | |||
3 | In [1]: %gui [backend] |
|
3 | In [1]: %gui [backend] | |
4 |
|
4 | |||
5 | In [2]: %run switchgui [backend] |
|
5 | In [2]: %run switchgui [backend] | |
6 |
|
6 | |||
7 | where the optional backend can be one of: qt4, gtk, tk, wx. |
|
7 | where the optional backend can be one of: qt4, gtk, tk, wx. | |
|
8 | ||||
|
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. | |||
8 | """ |
|
14 | """ | |
9 |
|
15 | |||
10 | import sys |
|
16 | import sys | |
11 | import time |
|
17 | import time | |
12 |
|
18 | |||
13 | from IPython.lib import inputhook |
|
19 | from IPython.lib import inputhook | |
14 |
|
20 | |||
15 | gui = inputhook.current_gui() |
|
21 | gui = inputhook.current_gui() | |
16 | if gui is None: |
|
22 | if gui is None: | |
17 | gui = 'qt4' |
|
23 | gui = 'qt4' | |
18 | inputhook.enable_qt4(app=True) |
|
24 | inputhook.enable_qt4(app=True) | |
19 |
|
25 | |||
20 | backends = dict(wx='wxagg', qt4='qt4agg', gtk='gtkagg', tk='tkagg') |
|
26 | backends = dict(wx='wxagg', qt4='qt4agg', gtk='gtkagg', tk='tkagg') | |
21 |
|
27 | |||
22 | import matplotlib |
|
28 | import matplotlib | |
23 | matplotlib.use(backends[gui]) |
|
29 | matplotlib.use(backends[gui]) | |
24 | matplotlib.interactive(True) |
|
30 | matplotlib.interactive(True) | |
25 |
|
31 | |||
26 | import matplotlib |
|
32 | import matplotlib | |
27 | from matplotlib import pyplot as plt, mlab, pylab |
|
33 | from matplotlib import pyplot as plt, mlab, pylab | |
28 | import numpy as np |
|
34 | import numpy as np | |
29 |
|
35 | |||
30 | from numpy import * |
|
36 | from numpy import * | |
31 | from matplotlib.pyplot import * |
|
37 | from matplotlib.pyplot import * | |
32 |
|
38 | |||
33 | x = np.linspace(0,pi,500) |
|
39 | x = np.linspace(0,pi,500) | |
34 |
|
40 | |||
35 | print "A plot has been created" |
|
41 | print "A plot has been created" | |
36 | line, = plot(x,sin(2*x)) |
|
42 | line, = plot(x,sin(2*x)) | |
37 | inputhook.spin() |
|
43 | inputhook.spin() # This has to be removed for Tk | |
38 |
|
44 | |||
39 |
|
45 | |||
40 | print "Now, we will update the plot..." |
|
46 | print "Now, we will update the plot..." | |
41 |
|
47 | |||
42 | for i in range(1,51): |
|
48 | for i in range(1,51): | |
43 | print i, |
|
49 | print i, | |
44 | sys.stdout.flush() |
|
50 | sys.stdout.flush() | |
45 | line.set_data(x,sin(x*i)) |
|
51 | line.set_data(x,sin(x*i)) | |
46 | plt.title('i=%d' % i) |
|
52 | plt.title('i=%d' % i) | |
47 | plt.draw() |
|
53 | plt.draw() | |
48 | inputhook.spin() |
|
54 | inputhook.spin() # This has to be removed for Tk |
General Comments 0
You need to be logged in to leave comments.
Login now