Skip to content

Commit bebb3a9

Browse files
committed
added Printf
svn path=/trunk/matplotlib/; revision=714
1 parent bbb8abe commit bebb3a9

File tree

11 files changed

+337
-189
lines changed

11 files changed

+337
-189
lines changed

API_CHANGES

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
API CHANGES in matplotlib-0.65
2+
3+
Did away with the text methods for angle since they were ambiguous.
4+
fontangle could mean fontstyle (obligue, etc) or the rotation of the
5+
text. Use style and rotation instead.
6+
7+
18
API CHANGES in matplotlib-0.63
29

310
Dates are now represented internally as float days since 0001-01-01,

examples/text_handles.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
#Controlling the properties of axis text using handles
33

4-
# See axis_text_themes.py for a more elegant, pythonic way to control
4+
# See examples/text_themes.py for a more elegant, pythonic way to control
55
# fonts. After all, if we were slaves to matlab , we wouldn't be
66
# using python!
77

@@ -24,17 +24,7 @@ def f(t):
2424
ytext = ylabel('Damped oscillation')
2525
xtext = xlabel('time (s)')
2626

27-
set(ttext, 'fontsize', 'large')
28-
set(ttext, 'color', 'r')
29-
set(ttext, 'fontangle', 'italic')
30-
31-
set(xtext, 'fontsize', 'medium')
32-
set(xtext, 'fontname', 'courier')
33-
set(xtext, 'fontweight', 'bold')
34-
set(xtext, 'color', 'g')
35-
36-
set(ytext, 'fontsize', 'medium')
37-
set(ytext, 'fontname', 'helvetica')
38-
set(ytext, 'fontweight', 'light')
39-
set(ytext, 'color', 'b')
27+
set(ttext, size='large', color='r', style='italic')
28+
set(xtext, size='medium', name='courier', weight='bold', color='g')
29+
set(ytext, size='medium', name='helvetica', weight='light', color='b')
4030
show()

examples/text_themes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
font = {'family' : 'serif',
55
'color' : 'r',
6-
'fontweight' : 'normal',
7-
'fontsize' : 12,
6+
'weight' : 'normal',
7+
'size' : 12,
88
}
99

1010
def f(t):
@@ -16,9 +16,9 @@ def f(t):
1616
t2 = arange(0.0, 5.0, 0.02)
1717

1818
plot(t1, f(t1), 'bo', t2, f(t2), 'k')
19-
title('Damped exponential decay', font, fontsize='large', color='r')
19+
title('Damped exponential decay', font, size='large', color='r')
2020
text(2, 0.65, 'cos(2 pi t) exp(-t)', font, color='k', family='monospace' )
21-
xlabel('time (s)', font, fontangle='italic')
21+
xlabel('time (s)', font, style='italic')
2222
ylabel('voltage (mV)', font)
2323

2424
#savefig('text_themes')

lib/matplotlib/artist.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
from cbook import True, False
44
from transforms import identity_transform
55

6+
## Note, matplotlib artists use the doc strings for set and get
7+
# methods to enable the introspection methods of set and get in the
8+
# matlab interface Every set_ to be controlled by the set function
9+
# method should have a docstring containing the line
10+
#
11+
# ACCEPTS: [ legal | values ]
12+
#
13+
# and aliases for setters and getters should have a docstring that
14+
# starts with 'alias for ', as in 'alias for set_somemethod'
15+
#
16+
# You may wonder why we use so much boiler-plate manually defining the
17+
# set_alias and get_alias functions, rather than using some clever
18+
# python trick. The answer is that I need to be able to manipulate
19+
# the docstring, and there is no clever way to do that in python 2.2,
20+
# as far as I can see - see
21+
# http://groups.google.com/groups?hl=en&lr=&threadm=mailman.5090.1098044946.5135.python-list%40python.org&rnum=1&prev=/groups%3Fq%3D__doc__%2Bauthor%253Ajdhunter%2540ace.bsd.uchicago.edu%26hl%3Den%26btnG%3DGoogle%2BSearch
22+
23+
624
class Artist:
725
"""
826
Abstract base class for someone who renders into a FigureCanvas
@@ -59,8 +77,8 @@ def set_clip_box(self, clipbox):
5977

6078
def get_alpha(self):
6179
"""
62-
Return the alpha value used for blending - not supported on
63-
all backends
80+
Return the alpha value used for blending - not supported on all
81+
backends
6482
"""
6583
return self._alpha
6684

lib/matplotlib/lines.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ def set_aa(self, val):
769769
'alias for set_antialiased'
770770
self.set_antialiased(val)
771771

772-
773772
def set_c(self, val):
774773
'alias for set_color'
775774
self.set_color(val)
@@ -804,3 +803,40 @@ def set_ms(self, val):
804803
'alias for set_markersize'
805804
self.set_markersize(val)
806805

806+
def get_aa(self):
807+
'alias for get_antialiased'
808+
return self.get_antialiased()
809+
810+
def get_c(self):
811+
'alias for get_color'
812+
return self.get_color()
813+
814+
815+
def get_ls(self):
816+
'alias for get_linestyle'
817+
return self.get_linestyle()
818+
819+
820+
def get_lw(self):
821+
'alias for get_linewidth'
822+
return self.get_linewidth()
823+
824+
825+
def get_mec(self):
826+
'alias for get_markeredgecolor'
827+
return self.get_markeredgecolor()
828+
829+
830+
def get_mew(self):
831+
'alias for get_markeredgewidth'
832+
return self.get_markeredgewidth()
833+
834+
835+
def get_mfc(self):
836+
'alias for get_markerfacecolor'
837+
return self.get_markerfacecolor()
838+
839+
840+
def get_ms(self):
841+
'alias for get_markersize'
842+
return self.get_markersize()

lib/matplotlib/matlab.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,10 @@ def get_aliases(self):
10221022
aliases = {}
10231023
for name in names:
10241024
func = getattr(self.o, name)
1025+
if not self.is_alias(func): continue
10251026
docstring = func.__doc__
1026-
if docstring is None: continue
1027-
if docstring.startswith('alias for '):
1028-
fullname = docstring[10:]
1029-
aliases[fullname[4:]] = name[4:]
1027+
fullname = docstring[10:]
1028+
aliases[fullname[4:]] = name[4:]
10301029
return aliases
10311030

10321031
def get_valid_values(self, attr):
@@ -1039,13 +1038,14 @@ def get_valid_values(self, attr):
10391038

10401039
name = 'set_%s'%attr
10411040
if not hasattr(self.o, name):
1042-
raise AttributeError('%s has no function %s'%(h,name))
1041+
raise AttributeError('%s has no function %s'%(self.o,name))
10431042
func = getattr(self.o, name)
10441043

10451044
docstring = func.__doc__
10461045
if docstring is None: return 'unknown'
10471046

1048-
if docstring.startswith('alias'): return docstring
1047+
if docstring.startswith('alias for '):
1048+
return None
10491049
for line in docstring.split('\n'):
10501050
line = line.lstrip()
10511051
if not line.startswith('ACCEPTS:'): continue
@@ -1057,10 +1057,21 @@ def get_setters(self):
10571057
Get the attribute strings with setters for object h
10581058
"""
10591059

1060-
return [name[4:] for name in dir(self.o)
1061-
if name.startswith('set_') and
1062-
callable(getattr(self.o,name))]
1063-
1060+
setters = []
1061+
for name in dir(self.o):
1062+
if not name.startswith('set_'): continue
1063+
o = getattr(self.o,name)
1064+
if not callable(o): continue
1065+
func = o
1066+
if self.is_alias(func): continue
1067+
setters.append(name[4:])
1068+
return setters
1069+
1070+
def is_alias(self, o):
1071+
ds = o.__doc__
1072+
if ds is None: return False
1073+
return ds.startswith('alias for ')
1074+
10641075
def aliased_name(self, s):
10651076
"""
10661077
return 'fullname or alias' if s has an alias.
@@ -1083,8 +1094,9 @@ def pprint_setters(self, property=None):
10831094
return ' %s: %s' %(property, accepts)
10841095

10851096
attrs = self.get_setters()
1086-
lines = []
10871097
attrs.sort()
1098+
lines = []
1099+
10881100
for property in attrs:
10891101
accepts = self.get_valid_values(property)
10901102
name = self.aliased_name(property)
@@ -1102,10 +1114,9 @@ def pprint_getters(self):
11021114
lines = []
11031115
for name in getters:
11041116
func = getattr(self.o, name)
1105-
docstring = func.__doc__
1106-
if docstring is not None and docstring.startswith('alias'): continue
1117+
if self.is_alias(func): continue
11071118
try: val = func()
1108-
except: pass
1119+
except: continue
11091120
if iterable(val) and len(val)>6:
11101121
s = str(val[:6]) + '...'
11111122
else:

lib/matplotlib/patches.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ def get_window_extent(self, renderer=None):
135135
verts = self.get_verts()
136136
tverts = self._transform.seq_xy_tups(verts)
137137
return bound_vertices(tverts)
138+
139+
140+
141+
def set_lw(self, val):
142+
'alias for set_linewidth'
143+
self.set_linewidth(val)
144+
145+
146+
def set_ec(self, val):
147+
'alias for set_edgecolor'
148+
self.set_edgecolor(val)
149+
150+
151+
def set_fc(self, val):
152+
'alias for set_facecolor'
153+
self.set_facecolor(val)
154+
155+
156+
def get_aa(self):
157+
'alias for get_antialiased'
158+
return self.get_antialiased()
159+
160+
161+
def get_lw(self):
162+
'alias for get_linewidth'
163+
return self.get_linewidth()
164+
165+
166+
def get_ec(self):
167+
'alias for get_edgecolor'
168+
return self.get_edgecolor()
169+
170+
171+
def get_fc(self):
172+
'alias for get_facecolor'
173+
return self.get_facecolor()
138174

139175
class Rectangle(Patch):
140176
"""
@@ -323,22 +359,3 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
323359
r.set_clip_on( False )
324360
r.draw(renderer)
325361

326-
327-
def set_aa(self, val):
328-
'alias for set_antialiased'
329-
self.set_antialiased(val)
330-
331-
332-
def set_lw(self, val):
333-
'alias for set_linewidth'
334-
self.set_linewidth(val)
335-
336-
337-
def set_ec(self, val):
338-
'alias for set_edgecolor'
339-
self.set_edgecolor(val)
340-
341-
342-
def set_fc(self, val):
343-
'alias for set_facecolor'
344-
self.set_facecolor(val)

0 commit comments

Comments
 (0)