@@ -138,25 +138,27 @@ def _clear_color_cycle(self):
138
138
self .count = 0
139
139
140
140
def __call__ (self , * args , ** kwargs ):
141
-
141
+
142
142
ret = self ._grab_next_args (* args , ** kwargs )
143
143
return ret
144
144
145
145
def set_lineprops (self , line , ** kwargs ):
146
146
assert self .command == 'plot' , 'set_lineprops only works with "plot"'
147
147
for key , val in kwargs .items ():
148
148
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 )
152
153
153
154
def set_patchprops (self , fill_poly , ** kwargs ):
154
155
assert self .command == 'fill' , 'set_patchprops only works with "fill"'
155
156
for key , val in kwargs .items ():
156
157
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 )
160
162
161
163
162
164
def is_filled (self , marker ):
@@ -296,8 +298,7 @@ class Axes(Artist):
296
298
297
299
def __init__ (self , fig , rect ,
298
300
axisbg = None , # defaults to rc axes.facecolor
299
- frameon = True ,
300
- ** kwargs ):
301
+ frameon = True ):
301
302
Artist .__init__ (self )
302
303
303
304
@@ -928,7 +929,7 @@ def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none,
928
929
929
930
return pxy , freqs
930
931
931
- def draw (self , renderer , * args , ** kwargs ):
932
+ def draw (self , renderer ):
932
933
"Draw everything (plot lines, axes, labels)"
933
934
934
935
renderer .open_group ('axes' )
@@ -1440,18 +1441,29 @@ def legend(self, *args, **kwargs):
1440
1441
loc = 0, 1 is left top
1441
1442
loc = 0.5, 0.5 is center, center
1442
1443
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
1444
1455
"""
1445
1456
1446
- loc = kwargs .get ('loc' , 1 )
1447
1457
if len (args )== 0 :
1448
1458
labels = [line .get_label () for line in self .lines ]
1449
1459
lines = self .lines
1460
+ loc = kwargs .pop ('loc' , 1 )
1450
1461
1451
1462
elif len (args )== 1 :
1452
1463
# LABELS
1453
1464
labels = args [0 ]
1454
1465
lines = [line for line , label in zip (self .lines , labels )]
1466
+ loc = kwargs .pop ('loc' , 1 )
1455
1467
1456
1468
elif len (args )== 2 :
1457
1469
if is_string_like (args [1 ]) or isinstance (args [1 ], int ):
@@ -1461,6 +1473,7 @@ def legend(self, *args, **kwargs):
1461
1473
else :
1462
1474
# LINES, LABELS
1463
1475
lines , labels = args
1476
+ loc = kwargs .pop ('loc' , 1 )
1464
1477
1465
1478
elif len (args )== 3 :
1466
1479
# LINES, LABELS, LOC
@@ -1469,7 +1482,7 @@ def legend(self, *args, **kwargs):
1469
1482
raise RuntimeError ('Invalid arguments to legend' )
1470
1483
1471
1484
lines = flatten (lines )
1472
- self .legend_ = Legend (self , lines , labels , loc )
1485
+ self .legend_ = Legend (self , lines , labels , loc , ** kwargs )
1473
1486
return self .legend_
1474
1487
1475
1488
def loglog (self , * args , ** kwargs ):
@@ -1493,11 +1506,11 @@ def loglog(self, *args, **kwargs):
1493
1506
* subsy: the location of the minor yticks; None defaults to range(2,basey)
1494
1507
"""
1495
1508
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 ),
1498
1511
}
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 ),
1501
1514
}
1502
1515
1503
1516
self .set_xscale ('log' , ** dx )
@@ -1583,12 +1596,14 @@ def pcolor(self, *args, **kwargs):
1583
1596
"""
1584
1597
if not self ._hold : self .cla ()
1585
1598
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 ]
1592
1607
1593
1608
if len (args )== 1 :
1594
1609
C = args [0 ]
@@ -1597,7 +1612,7 @@ def pcolor(self, *args, **kwargs):
1597
1612
elif len (args )== 3 :
1598
1613
X , Y , C = args
1599
1614
else :
1600
- raise RuntimeError ( 'Illegal arguments to pcolor; see help(pcolor)' )
1615
+ raise TypeError , 'Illegal arguments to pcolor; see help(pcolor)'
1601
1616
1602
1617
Nx , Ny = X .shape
1603
1618
patches = []
@@ -1701,7 +1716,12 @@ def pcolor_classic(self, *args, **kwargs):
1701
1716
"""
1702
1717
1703
1718
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 ]
1705
1725
1706
1726
if len (args )== 1 :
1707
1727
C = args [0 ]
@@ -1710,18 +1730,13 @@ def pcolor_classic(self, *args, **kwargs):
1710
1730
elif len (args )== 3 :
1711
1731
X , Y , C = args
1712
1732
else :
1713
- raise RuntimeError ( 'Illegal arguments to pcolor; see help(pcolor)' )
1733
+ raise TypeError , 'Illegal arguments to pcolor; see help(pcolor)'
1714
1734
1715
-
1716
1735
Nx , Ny = X .shape
1717
1736
1718
- cmap = kwargs .get ('cmap' , cm .get_cmap ())
1719
- norm = kwargs .get ('norm' , normalize ())
1720
1737
if isinstance (norm , normalize ) and not norm .scaled ():
1721
1738
norm .autoscale (C )
1722
1739
1723
-
1724
- alpha = kwargs .get ('alpha' , 1.0 )
1725
1740
nc = norm (C )
1726
1741
RGBA = cmap (nc , alpha )
1727
1742
@@ -2210,8 +2225,8 @@ def semilogx(self, *args, **kwargs):
2210
2225
2211
2226
"""
2212
2227
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 ),
2215
2230
}
2216
2231
2217
2232
self .set_xscale ('log' , ** d )
@@ -2236,8 +2251,8 @@ def semilogy(self, *args, **kwargs):
2236
2251
range(2,basey)
2237
2252
2238
2253
"""
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 ),
2241
2256
}
2242
2257
2243
2258
self .set_yscale ('log' , ** d )
@@ -2755,7 +2770,7 @@ class SubplotBase:
2755
2770
Subplot(211) # 2 rows, 1 column, first (upper) plot
2756
2771
"""
2757
2772
2758
- def __init__ (self , * args , ** kwargs ):
2773
+ def __init__ (self , * args ):
2759
2774
# Axes __init__ below
2760
2775
2761
2776
if len (args )== 1 :
@@ -2825,7 +2840,7 @@ class Subplot(SubplotBase, Axes):
2825
2840
Subplot(211) # 2 rows, 1 column, first (upper) plot
2826
2841
"""
2827
2842
def __init__ (self , fig , * args , ** kwargs ):
2828
- SubplotBase .__init__ (self , * args , ** kwargs )
2843
+ SubplotBase .__init__ (self , * args )
2829
2844
Axes .__init__ (self , fig , [self .figLeft , self .figBottom , self .figW , self .figH ], ** kwargs )
2830
2845
2831
2846
@@ -3143,6 +3158,6 @@ class PolarSubplot(SubplotBase, PolarAxes):
3143
3158
Subplot(211) # 2 rows, 1 column, first (upper) plot
3144
3159
"""
3145
3160
def __init__ (self , fig , * args , ** kwargs ):
3146
- SubplotBase .__init__ (self , * args , ** kwargs )
3161
+ SubplotBase .__init__ (self , * args )
3147
3162
PolarAxes .__init__ (self , fig , [self .figLeft , self .figBottom , self .figW , self .figH ], ** kwargs )
3148
3163
0 commit comments