Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd0e1f3

Browse files
committed
lots of interactive fixes and an INTERACTIVE howto
svn path=/trunk/matplotlib/; revision=13
1 parent e9074c8 commit cd0e1f3

5 files changed

Lines changed: 127 additions & 9 deletions

File tree

INTERACTIVE

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
To use matplotlib interactively from the prompt, you need a special
2+
interpreter that doesn't enter the gtk mainloop. One is provided in
3+
examples/interactive.py. The coew functionality of this interpreter
4+
was provided by Brian McErlean and John Finlay. See the header for
5+
more info.
6+
7+
This will only work if you have pygtk compiled with threading. See
8+
instrubtions below.
9+
10+
WIN32 Users
11+
12+
I haven't tested the interactive shell on win32. It is apparently
13+
possible, but not easy, to get threading to work on win32. See
14+
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq21.003.htp
15+
16+
LINUX/UNIX Users:
17+
18+
To compile pygtk with threading, I recommend you make a backup of your
19+
existing pygtk install tree and completely remove it
20+
21+
eg
22+
> cd /your/path/to/python/site-packages
23+
> cp -a gtk-2.0 /some/backup/dir
24+
> rm -rf gtk-2.0
25+
26+
This is because I have found that recompiling pygtk with threads on top
27+
of an existing installation w/o threads does not enable threads. Your
28+
milage may vary.
29+
30+
Then from a clean pygtk src tree
31+
32+
> ./configure --enable-thread # and any other flags
33+
> make install
34+
35+
TESTING threading
36+
37+
To test whether this install worked, try running this script
38+
39+
import pygtk
40+
pygtk.require('2.0')
41+
import gtk
42+
43+
import threading, time
44+
45+
def func():
46+
n = 0
47+
while 1:
48+
print n
49+
n += 1
50+
time.sleep(0.1)
51+
52+
gtk.threads_init()
53+
threading.Thread(target=func).start()
54+
gtk.mainloop()
55+
56+
57+
58+
If it spits numbers back at you, you're golden.
59+
60+
TESTING with matplotlib
61+
62+
You should be able to make a simple plot with
63+
64+
> cd examples
65+
> ./interactive.py
66+
Welcome to matplotlib.
67+
68+
help(matlab) -- shows a list of all matlab compatible commands provided
69+
help(plotting) -- shows a list of plot specific commands
70+
71+
>> plot([1,2,3])
72+
73+
74+

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ INSTALL
1717

1818
If you have the requirements, just do 'python setup.py install'.
1919

20+
If you want to use matplotlib interactively from the prompt, see
21+
INTERACTIVE
22+
23+
2024
EXAMPLES
2125

2226
See the examples in the examples dir.

TODO

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
command line, but the GUI needs to be updated to allow resolution
88
to be set along with filename
99

10-
-- fix text size calculations using pango layouts: DONE
10+
-- fix text size calculations using pango layouts:
11+
12+
DONE
1113

1214
-- add a font selection dialog for the axis text
1315

14-
-- enable vertical rendering for ylabels: DONE
16+
-- enable vertical rendering for ylabels:
17+
18+
DONE
1519

1620
-- enable anti aliasing for fonts: DONE with pango
1721

@@ -21,7 +25,9 @@
2125
-- add a color selection dialog for the background, lines, and text
2226

2327
-- allow interactive control of the plot from the python shell after
24-
it has been launched using the cookbook thread recipe. DONE
28+
it has been launched using the cookbook thread recipe.
29+
30+
DONE
2531

2632
-- write a user guide
2733

@@ -36,7 +42,7 @@
3642
working cross platform. According to the docs this is better
3743
handled using size hints -- but I don't know how to use them, yet.
3844

39-
-- vlines and hlines disappear on in some instance due to improper
45+
-- vlines and hlines disappear in some instance due to improper
4046
clipping
4147

4248
-- One the errorbar demo the hlines do not always appear symmetric
@@ -45,8 +51,13 @@
4551

4652
-- Clip patches outside view port
4753

54+
DONE
55+
4856
-- Allow background color to be set for subplots
4957

58+
DONE: subplot now takes a kwarg axisbg with color format string
59+
just as axes does
60+
5061
-- Expose bug on win32 for axis text
5162

5263
-- Fix floating point bug on panx/pany where 0 is computed as 5e-17
@@ -60,5 +71,32 @@
6071

6172
plot(t1, p1, 'o', t2, p2, ogtt.times, ogtt.cpeptide, 's')
6273

74+
DONE: 2003-05-12 fixed _grab_next_args in figure.py
75+
6376
-- xlabel is lower than it needs to be
6477

78+
UPDATE: made a change -- make sure this works
79+
80+
-- interactive setting of x/ylabels doesn't redraw all labels unless
81+
you click a forced redraw
82+
83+
DONE 2003-05-12 Removed some of the state handling of text labels
84+
so they always redraw
85+
86+
-- When you change a property using the OO interface in interactive,
87+
the figure doesn't know to redraw.
88+
89+
Some possibilities:
90+
91+
1) redraw on all interactive commands. kind of heavy handled
92+
93+
2) override setattr on artist to signal a redraw event. kind of
94+
heavy handled
95+
96+
3) allow derived classes to signal redraw events when nexessary.
97+
kind of code intrusive.
98+
99+
100+
-- on exit from interactive.py call gtk. mainquit
101+
102+
-- pan zoom on axes_demo flushes insets

examples/axes_demo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
axis([0, 1, 1.1*min(s), 2*max(s) ])
1919
xlabel('time (s)')
2020
ylabel('current (nA)')
21-
2221
title('Gaussian white noise convolved with an exponential function')
2322

2423
# Make a histogram probability density inset
@@ -38,5 +37,4 @@
3837
set(a, 'xticks', [])
3938
set(a, 'yticks', [])
4039

41-
4240
show()

examples/interactive.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,22 @@ def signal_handler (*args):
178178
interpreter.feed ("from matplotlib import matlab")
179179
interpreter.feed ("from matplotlib.matlab import *")
180180
interpreter.feed ("sys.path.append('.')")
181+
182+
# turn off rendering until end of script
183+
matplotlib.matlab.interactive = 0
181184
if len (sys.argv) > 1:
182185
for line in file(sys.argv[1], 'r'):
183-
print '>>', line.rstrip(),
186+
if line.lstrip().find('show()')==0: continue
187+
print '>>', line.rstrip()
184188
interpreter.feed(line)
185-
gcf().draw()
189+
#gcf().draw()
190+
interpreter.feed ("ShowOn().set(1)")
186191
print """Welcome to matplotlib.
187192
188193
help(matlab) -- shows a list of all matlab compatible commands provided
189194
help(plotting) -- shows a list of plot specific commands
190195
"""
191196

192-
matplotlib.matlab.interactive = 1
193197

194198
try:
195199
while 1:

0 commit comments

Comments
 (0)