Skip to content

Commit 8c776a3

Browse files
committed
applied norberts legend patches
svn path=/trunk/matplotlib/; revision=707
1 parent 15996be commit 8c776a3

File tree

6 files changed

+116
-71
lines changed

6 files changed

+116
-71
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 applied Norbert's patched and exposed legend configuration
4+
to kwargs - JDH
5+
36
2004-11-23 backend_gtk.py: added a default exception handler
47

58
2004-11-18 backend_gtk.py: change so that the backend knows about all image

lib/matplotlib/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ def get_home():
286286

287287
def _get_data_path():
288288
'get the path to matplotlib data'
289+
290+
if os.environ.has_key('MATPLOTLIBDATA'):
291+
path = os.environ['MATPLOTLIBDATA']
292+
if os.path.isdir(path): return path
293+
289294
path = os.path.join(distutils.sysconfig.PREFIX, 'share', 'matplotlib')
290295
if os.path.isdir(path): return path
291296

@@ -297,10 +302,6 @@ def _get_data_path():
297302
'share','matplotlib')
298303
if os.path.isdir(path): return path
299304

300-
if os.environ.has_key('MATPLOTLIBDATA'):
301-
path = os.environ['MATPLOTLIBDATA']
302-
if os.path.isdir(path): return path
303-
304305

305306
# CODE ADDED TO SUPPORT PY2EXE - you will need to copy
306307
# C:\Python23\share\matplotlib into your dist dir. See
@@ -459,7 +460,7 @@ def validate_verbose_erro(s):
459460
defaultParams = {
460461
'backend' : ['GTK', str],
461462
'numerix' : ['Numeric', validate_numerix],
462-
'toolbar' : ['classic', validate_toolbar],
463+
'toolbar' : ['toolbar2', validate_toolbar],
463464
'datapath' : [get_data_path(), validate_path_exists],
464465
'interactive' : [False, validate_bool],
465466
'timezone' : ['UTC', str],

lib/matplotlib/axes.py

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,27 @@ def _clear_color_cycle(self):
138138
self.count = 0
139139

140140
def __call__(self, *args, **kwargs):
141-
141+
142142
ret = self._grab_next_args(*args, **kwargs)
143143
return ret
144144

145145
def set_lineprops(self, line, **kwargs):
146146
assert self.command == 'plot', 'set_lineprops only works with "plot"'
147147
for key, val in kwargs.items():
148148
funcName = "set_%s"%key
149-
if hasattr(line,funcName):
150-
func = getattr(line,funcName)
151-
func(val)
149+
if not hasattr(line,funcName):
150+
raise TypeError, 'There is no line property "%s"'%key
151+
func = getattr(line,funcName)
152+
func(val)
152153

153154
def set_patchprops(self, fill_poly, **kwargs):
154155
assert self.command == 'fill', 'set_patchprops only works with "fill"'
155156
for key, val in kwargs.items():
156157
funcName = "set_%s"%key
157-
if hasattr(fill_poly,funcName):
158-
func = getattr(fill_poly,funcName)
159-
func(val)
158+
if not hasattr(fill_poly,funcName):
159+
raise TypeError, 'There is no patch property "%s"'%key
160+
func = getattr(fill_poly,funcName)
161+
func(val)
160162

161163

162164
def is_filled(self, marker):
@@ -296,8 +298,7 @@ class Axes(Artist):
296298

297299
def __init__(self, fig, rect,
298300
axisbg = None, # defaults to rc axes.facecolor
299-
frameon = True,
300-
**kwargs):
301+
frameon = True):
301302
Artist.__init__(self)
302303

303304

@@ -928,7 +929,7 @@ def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
928929

929930
return pxy, freqs
930931

931-
def draw(self, renderer, *args, **kwargs):
932+
def draw(self, renderer):
932933
"Draw everything (plot lines, axes, labels)"
933934

934935
renderer.open_group('axes')
@@ -1440,18 +1441,29 @@ def legend(self, *args, **kwargs):
14401441
loc = 0, 1 is left top
14411442
loc = 0.5, 0.5 is center, center
14421443
1443-
and so on
1444+
and so on. The following kwargs are supported
1445+
1446+
numpoints = 4 # the number of points in the legend line
1447+
prop = FontProperties('smaller') # the font properties
1448+
pad = 0.2 # the fractional whitespace inside the legend border
1449+
1450+
# The kwarg dimensions are in axes coords
1451+
labelsep = 0.005 # the vertical space between the legend entries
1452+
handlelen = 0.05 # the length of the legend lines
1453+
handletextsep = 0.02 # the space between the legend line and legend text
1454+
axespad = 0.02 # the border between the axes and legend edge
14441455
"""
14451456

1446-
loc = kwargs.get('loc', 1)
14471457
if len(args)==0:
14481458
labels = [line.get_label() for line in self.lines]
14491459
lines = self.lines
1460+
loc = kwargs.pop('loc', 1)
14501461

14511462
elif len(args)==1:
14521463
# LABELS
14531464
labels = args[0]
14541465
lines = [line for line, label in zip(self.lines, labels)]
1466+
loc = kwargs.pop('loc', 1)
14551467

14561468
elif len(args)==2:
14571469
if is_string_like(args[1]) or isinstance(args[1], int):
@@ -1461,6 +1473,7 @@ def legend(self, *args, **kwargs):
14611473
else:
14621474
# LINES, LABELS
14631475
lines, labels = args
1476+
loc = kwargs.pop('loc', 1)
14641477

14651478
elif len(args)==3:
14661479
# LINES, LABELS, LOC
@@ -1469,7 +1482,7 @@ def legend(self, *args, **kwargs):
14691482
raise RuntimeError('Invalid arguments to legend')
14701483

14711484
lines = flatten(lines)
1472-
self.legend_ = Legend(self, lines, labels, loc)
1485+
self.legend_ = Legend(self, lines, labels, loc, **kwargs)
14731486
return self.legend_
14741487

14751488
def loglog(self, *args, **kwargs):
@@ -1493,11 +1506,11 @@ def loglog(self, *args, **kwargs):
14931506
* subsy: the location of the minor yticks; None defaults to range(2,basey)
14941507
"""
14951508
if not self._hold: self.cla()
1496-
dx = {'basex': kwargs.get('basex', 10),
1497-
'subsx': kwargs.get('subsx', None),
1509+
dx = {'basex': kwargs.pop('basex', 10),
1510+
'subsx': kwargs.pop('subsx', None),
14981511
}
1499-
dy = {'basey': kwargs.get('basey', 10),
1500-
'subsy': kwargs.get('subsy', None),
1512+
dy = {'basey': kwargs.pop('basey', 10),
1513+
'subsy': kwargs.pop('subsy', None),
15011514
}
15021515

15031516
self.set_xscale('log', **dx)
@@ -1583,12 +1596,14 @@ def pcolor(self, *args, **kwargs):
15831596
"""
15841597
if not self._hold: self.cla()
15851598

1586-
alpha = kwargs.get('alpha', 1.0)
1587-
norm = kwargs.get('norm')
1588-
cmap = kwargs.get('cmap')
1589-
vmin = kwargs.get('vmin')
1590-
vmax = kwargs.get('vmax')
1591-
shading = kwargs.get('shading', 'faceted')
1599+
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')
1604+
shading = kwargs.pop('shading', 'faceted')
1605+
if len(kwargs):
1606+
raise TypeError, 'Unknown argument "%s"'%kwargs.keys()[0]
15921607

15931608
if len(args)==1:
15941609
C = args[0]
@@ -1597,7 +1612,7 @@ def pcolor(self, *args, **kwargs):
15971612
elif len(args)==3:
15981613
X, Y, C = args
15991614
else:
1600-
raise RuntimeError('Illegal arguments to pcolor; see help(pcolor)')
1615+
raise TypeError, 'Illegal arguments to pcolor; see help(pcolor)'
16011616

16021617
Nx, Ny = X.shape
16031618
patches = []
@@ -1701,7 +1716,12 @@ def pcolor_classic(self, *args, **kwargs):
17011716
"""
17021717

17031718
if not self._hold: self.cla()
1704-
shading = kwargs.get('shading', 'faceted')
1719+
shading = kwargs.pop('shading', 'faceted')
1720+
cmap = kwargs.pop('cmap', cm.get_cmap())
1721+
norm = kwargs.pop('norm', normalize())
1722+
alpha = kwargs.pop('alpha', 1.0)
1723+
if len(kwargs):
1724+
raise TypeError, 'Unknown argument "%s"'%kwargs.keys()[0]
17051725

17061726
if len(args)==1:
17071727
C = args[0]
@@ -1710,18 +1730,13 @@ def pcolor_classic(self, *args, **kwargs):
17101730
elif len(args)==3:
17111731
X, Y, C = args
17121732
else:
1713-
raise RuntimeError('Illegal arguments to pcolor; see help(pcolor)')
1733+
raise TypeError, 'Illegal arguments to pcolor; see help(pcolor)'
17141734

1715-
17161735
Nx, Ny = X.shape
17171736

1718-
cmap = kwargs.get('cmap', cm.get_cmap())
1719-
norm = kwargs.get('norm', normalize())
17201737
if isinstance(norm, normalize) and not norm.scaled():
17211738
norm.autoscale(C)
17221739

1723-
1724-
alpha = kwargs.get('alpha', 1.0)
17251740
nc = norm(C)
17261741
RGBA = cmap(nc, alpha)
17271742

@@ -2210,8 +2225,8 @@ def semilogx(self, *args, **kwargs):
22102225
22112226
"""
22122227

2213-
d = {'basex': kwargs.get('basex', 10),
2214-
'subsx': kwargs.get('subsx', None),
2228+
d = {'basex': kwargs.pop('basex', 10),
2229+
'subsx': kwargs.pop('subsx', None),
22152230
}
22162231

22172232
self.set_xscale('log', **d)
@@ -2236,8 +2251,8 @@ def semilogy(self, *args, **kwargs):
22362251
range(2,basey)
22372252
22382253
"""
2239-
d = {'basey': kwargs.get('basey', 10),
2240-
'subsy': kwargs.get('subsy', None),
2254+
d = {'basey': kwargs.pop('basey', 10),
2255+
'subsy': kwargs.pop('subsy', None),
22412256
}
22422257

22432258
self.set_yscale('log', **d)
@@ -2755,7 +2770,7 @@ class SubplotBase:
27552770
Subplot(211) # 2 rows, 1 column, first (upper) plot
27562771
"""
27572772

2758-
def __init__(self, *args, **kwargs):
2773+
def __init__(self, *args):
27592774
# Axes __init__ below
27602775

27612776
if len(args)==1:
@@ -2825,7 +2840,7 @@ class Subplot(SubplotBase, Axes):
28252840
Subplot(211) # 2 rows, 1 column, first (upper) plot
28262841
"""
28272842
def __init__(self, fig, *args, **kwargs):
2828-
SubplotBase.__init__(self, *args, **kwargs)
2843+
SubplotBase.__init__(self, *args)
28292844
Axes.__init__(self, fig, [self.figLeft, self.figBottom, self.figW, self.figH], **kwargs)
28302845

28312846

@@ -3143,6 +3158,6 @@ class PolarSubplot(SubplotBase, PolarAxes):
31433158
Subplot(211) # 2 rows, 1 column, first (upper) plot
31443159
"""
31453160
def __init__(self, fig, *args, **kwargs):
3146-
SubplotBase.__init__(self, *args, **kwargs)
3161+
SubplotBase.__init__(self, *args)
31473162
PolarAxes.__init__(self, fig, [self.figLeft, self.figBottom, self.figW, self.figH], **kwargs)
31483163

lib/matplotlib/figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def draw(self, renderer):
265265
def get_axes(self):
266266
return self.axes
267267

268-
def legend(self, handles, labels, loc):
268+
def legend(self, handles, labels, loc, **kwargs):
269269
"""
270270
Place a legend in the figure. Labels are a sequence of
271271
strings, handles is a sequence of line or patch instances, and
@@ -296,7 +296,7 @@ def legend(self, handles, labels, loc):
296296

297297

298298
handles = flatten(handles)
299-
l = Legend(self, handles, labels, loc, isaxes=False)
299+
l = Legend(self, handles, labels, loc, isaxes=False, **kwargs)
300300
self._set_artist_props(l)
301301
self.legends.append(l)
302302
return l

0 commit comments

Comments
 (0)