Skip to content

Commit 34b6e9e

Browse files
committed
added set and get introspection
svn path=/trunk/matplotlib/; revision=708
1 parent 8c776a3 commit 34b6e9e

File tree

9 files changed

+609
-116
lines changed

9 files changed

+609
-116
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2004-11-23 Added matplotlib compatible set and get introspection. See
4+
set_and_get.py
5+
36
2004-11-23 applied Norbert's patched and exposed legend configuration
47
to kwargs - JDH
58

examples/set_and_get.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""
2+
3+
matlab (and matplotlib) allow you to use set and get to set and get
4+
object properties, as well as to do introspection on the object
5+
6+
set
7+
To set the linestyle of a line to be dashed, you can do
8+
9+
>>> line, = plot([1,2,3])
10+
>>> set(line, linestyle='--')
11+
12+
If you want to know the valid types of arguments, you can provide the
13+
name of the property you want to set without a value
14+
15+
>>> set(line, 'linestyle')
16+
linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
17+
18+
If you want to see all the properties that can be set, and their
19+
possible values, you can do
20+
21+
>>> set(line)
22+
23+
set operates on a single instance or a list of instances. If you are
24+
in quey mode introspecting the possible values, only the first
25+
instance in the sequnce is used. When actually setting values, all
26+
the instances will be set. Eg, suppose you have a list of two lines,
27+
the following will make both lines thicker and red
28+
29+
>>> x = arange(0,1.0,0.01)
30+
>>> y1 = sin(2*pi*x)
31+
>>> y2 = sin(4*pi*x)
32+
>>> lines = plot(x, y1, x, y2)
33+
>>> set(lines, linewidth=2, color='r')
34+
35+
36+
get:
37+
38+
get returns the value of a given attribute. You can use get to query
39+
the value of a single attribute
40+
41+
>>> get(line, 'linewidth')
42+
0.5
43+
44+
or all the attribute/value pairs
45+
46+
>>> get(line)
47+
aa = True
48+
alpha = 1.0
49+
antialiased = True
50+
c = b
51+
clip_on = True
52+
color = b
53+
... long listing skipped ...
54+
55+
Alisases:
56+
57+
To reduce keystrokes in interactive mode, a number of properties
58+
have short aliases, eg 'lw' for 'linewidth' and 'mec' for
59+
'markeredgecolor'. When calling set or get in introspection mode,
60+
these properties will be listed as 'fullname or aliasname', as in
61+
62+
63+
64+
65+
"""
66+
67+
from matplotlib.matlab import *
68+
69+
70+
x = arange(0,1.0,0.01)
71+
y1 = sin(2*pi*x)
72+
y2 = sin(4*pi*x)
73+
lines = plot(x, y1, x, y2)
74+
l1, l2 = lines
75+
set(lines, linestyle='--') # set both to dashed
76+
set(l1, linewidth=2, color='r') # line1 is thick and red
77+
set(l2, linewidth=1, color='g') # line2 is thicker and green
78+
79+
80+
print 'Line setters'
81+
set(l1)
82+
print 'Line getters'
83+
get(l1)
84+
85+
print 'Rectangle setters'
86+
set(gca().axesPatch)
87+
print 'Rectangle getters'
88+
get(gca().axesPatch)
89+
90+
t = title('Hi mom')
91+
print 'Text setters'
92+
set(t)
93+
print 'Text getters'
94+
get(t)

lib/matplotlib/artist.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ def is_transform_set(self):
2525
return self._transformSet
2626

2727
def set_transform(self, t):
28-
'set the Transformation instance used by this artist'
28+
"""
29+
set the Transformation instance used by this artist
30+
31+
ACCEPTS: a matplotlib.transform transformation instance
32+
"""
2933
self._transform = t
3034
self._transformSet = True
3135

@@ -38,13 +42,17 @@ def is_figure_set(self):
3842

3943
def set_figure(self, fig):
4044
"""
41-
Set the figure instance the artist belong to
45+
Set the figure instance the artist belong to
46+
47+
ACCEPTS: a matplotlib.figure.Figure instance
4248
"""
4349
self.figure = fig
4450

45-
def set_clip_box(self, clipbox):
51+
def set_clip_box(self, clipbox):
4652
"""
47-
Set the artist's clip Bbox
53+
Set the artist's clip Bbox
54+
55+
ACCEPTS: a matplotlib.transform.Bbox instance
4856
"""
4957
self.clipbox = clipbox
5058
self._clipon = clipbox is not None
@@ -65,7 +73,11 @@ def get_clip_on(self):
6573
return self._clipon and self.clipbox is not None
6674

6775
def set_clip_on(self, b):
68-
'Set whether artist uses clipping'
76+
"""
77+
Set whether artist uses clipping
78+
79+
ACCEPTS: [True | False]
80+
"""
6981
self._clipon = b
7082

7183
def draw(self, renderer, *args, **kwargs):
@@ -74,20 +86,28 @@ def draw(self, renderer, *args, **kwargs):
7486

7587
def set_alpha(self, alpha):
7688
"""
77-
Set the alpha value used for blending - not supported on
78-
all backends
89+
Set the alpha value used for blending - not supported on
90+
all backends
91+
92+
ACCEPTS: float
7993
"""
8094
self._alpha = alpha
8195

8296

8397
def set_lod(self, on):
8498
"""
85-
Set Level of Detail on or off. If on, the artists may examine
86-
things like the pixel width of the axes and draw a subset of
87-
their contents accordingly
99+
Set Level of Detail on or off. If on, the artists may examine
100+
things like the pixel width of the axes and draw a subset of
101+
their contents accordingly
102+
103+
ACCEPTS: [True | False]
88104
"""
89105
self._lod = on
90106

91107
def set_visible(self, b):
92-
"set the artist's visiblity"
108+
"""
109+
set the artist's visiblity
110+
111+
ACCEPTS: [True | False]
112+
"""
93113
self._visible = b

lib/matplotlib/axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,10 +1597,10 @@ def pcolor(self, *args, **kwargs):
15971597
if not self._hold: self.cla()
15981598

15991599
alpha = kwargs.pop('alpha', 1.0)
1600-
norm = kwargs.pop('norm')
1601-
cmap = kwargs.pop('cmap')
1602-
vmin = kwargs.pop('vmin')
1603-
vmax = kwargs.pop('vmax')
1600+
norm = kwargs.pop('norm', None)
1601+
cmap = kwargs.pop('cmap', None)
1602+
vmin = kwargs.pop('vmin', None)
1603+
vmax = kwargs.pop('vmax', None)
16041604
shading = kwargs.pop('shading', 'faceted')
16051605
if len(kwargs):
16061606
raise TypeError, 'Unknown argument "%s"'%kwargs.keys()[0]

lib/matplotlib/backends/backend_gtk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,8 @@ def exception_handler(type, value, tb):
15631563
if len(msg) :error_msg_gtk(msg)
15641564

15651565
# override excepthook only if it has not already been overridden
1566-
if sys.__excepthook__ is sys.excepthook:
1567-
sys.excepthook = exception_handler
1566+
#if sys.__excepthook__ is sys.excepthook:
1567+
# sys.excepthook = exception_handler
15681568

15691569
FigureManager = FigureManagerGTK
15701570
error_msg = error_msg_gtk

0 commit comments

Comments
 (0)