44
44
rcParams = matplotlib .rcParams
45
45
46
46
47
- def _plot_args_replacer (args , data ):
48
- if len (args ) == 1 :
49
- return ["y" ]
50
- elif len (args ) == 2 :
51
- # this can be two cases: x,y or y,c
52
- if (not args [1 ] in data and
53
- not (hasattr (data , 'dtype' ) and
54
- hasattr (data .dtype , 'names' ) and
55
- data .dtype .names is not None and
56
- args [1 ] in data .dtype .names )):
57
- # this is not in data, so just assume that it is something which
58
- # will not get replaced (color spec or array like).
59
- return ["y" , "c" ]
60
- # it's data, but could be a color code like 'ro' or 'b--'
61
- # -> warn the user in that case...
62
- try :
63
- _process_plot_format (args [1 ])
64
- except ValueError :
65
- pass
66
- else :
67
- cbook ._warn_external (
68
- "Second argument {!r} is ambiguous: could be a color spec but "
69
- "is in data; using as data. Either rename the entry in data "
70
- "or use three arguments to plot." .format (args [1 ]),
71
- RuntimeWarning )
72
- return ["x" , "y" ]
73
- elif len (args ) == 3 :
74
- return ["x" , "y" , "c" ]
75
- else :
76
- raise ValueError ("Using arbitrary long args with data is not "
77
- "supported due to ambiguity of arguments.\n Use "
78
- "multiple plotting calls instead." )
79
-
80
-
81
47
# The axes module contains all the wrappers to plotting functions.
82
48
# All the other methods should go in the _AxesBase class.
83
49
@@ -894,8 +860,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
894
860
895
861
@_preprocess_data (replace_names = ["positions" , "lineoffsets" ,
896
862
"linelengths" , "linewidths" ,
897
- "colors" , "linestyles" ],
898
- label_namer = None )
863
+ "colors" , "linestyles" ])
899
864
@docstring .dedent_interpd
900
865
def eventplot (self , positions , orientation = 'horizontal' , lineoffsets = 1 ,
901
866
linelengths = 1 , linewidths = None , colors = None ,
@@ -1111,10 +1076,8 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1111
1076
1112
1077
#### Basic plotting
1113
1078
1114
- # The label_naming happens in `matplotlib.axes._base._plot_args`
1115
- @_preprocess_data (replace_names = ["x" , "y" ],
1116
- positional_parameter_names = _plot_args_replacer ,
1117
- label_namer = None )
1079
+ # Uses a custom implementation of data-kwarg handling in
1080
+ # _process_plot_var_args.
1118
1081
@docstring .dedent_interpd
1119
1082
def plot (self , * args , scalex = True , scaley = True , ** kwargs ):
1120
1083
"""
@@ -1227,7 +1190,6 @@ def plot(self, *args, scalex=True, scaley=True, **kwargs):
1227
1190
You may suppress the warning by adding an empty format string
1228
1191
`plot('n', 'o', '', data=obj)`.
1229
1192
1230
-
1231
1193
Other Parameters
1232
1194
----------------
1233
1195
scalex, scaley : bool, optional, default: True
@@ -1254,13 +1216,11 @@ def plot(self, *args, scalex=True, scaley=True, **kwargs):
1254
1216
lines
1255
1217
A list of `.Line2D` objects representing the plotted data.
1256
1218
1257
-
1258
1219
See Also
1259
1220
--------
1260
1221
scatter : XY scatter plot with markers of variing size and/or color (
1261
1222
sometimes also called bubble chart).
1262
1223
1263
-
1264
1224
Notes
1265
1225
-----
1266
1226
**Format Strings**
@@ -1729,7 +1689,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
1729
1689
1730
1690
#### Specialized plotting
1731
1691
1732
- @_preprocess_data (replace_names = [ "x" , "y" ], label_namer = "y" )
1692
+ # @_preprocess_data() # let 'plot' do the unpacking..
1733
1693
def step (self , x , y , * args , where = 'pre' , ** kwargs ):
1734
1694
"""
1735
1695
Make a step plot.
@@ -1798,15 +1758,7 @@ def step(self, x, y, *args, where='pre', **kwargs):
1798
1758
1799
1759
return self .plot (x , y , * args , ** kwargs )
1800
1760
1801
- @_preprocess_data (replace_names = ["x" , "left" ,
1802
- "height" , "width" ,
1803
- "y" , "bottom" ,
1804
- "color" , "edgecolor" , "linewidth" ,
1805
- "tick_label" , "xerr" , "yerr" ,
1806
- "ecolor" ],
1807
- label_namer = None ,
1808
- replace_all_args = True
1809
- )
1761
+ @_preprocess_data ()
1810
1762
@docstring .dedent_interpd
1811
1763
def bar (self , x , height , width = 0.8 , bottom = None , * , align = "center" ,
1812
1764
** kwargs ):
@@ -2198,7 +2150,7 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
2198
2150
align = align , ** kwargs )
2199
2151
return patches
2200
2152
2201
- @_preprocess_data (label_namer = None )
2153
+ @_preprocess_data ()
2202
2154
@docstring .dedent_interpd
2203
2155
def broken_barh (self , xranges , yrange , ** kwargs ):
2204
2156
"""
@@ -2269,9 +2221,9 @@ def broken_barh(self, xranges, yrange, **kwargs):
2269
2221
2270
2222
return col
2271
2223
2272
- @_preprocess_data (replace_all_args = True , label_namer = None )
2273
- def stem (self , * args , linefmt = None , markerfmt = None , basefmt = None ,
2274
- bottom = 0 , label = None ):
2224
+ @_preprocess_data ()
2225
+ def stem (self , * args , linefmt = None , markerfmt = None , basefmt = None , bottom = 0 ,
2226
+ label = None ):
2275
2227
"""
2276
2228
Create a stem plot.
2277
2229
@@ -2429,8 +2381,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
2429
2381
2430
2382
return stem_container
2431
2383
2432
- @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ],
2433
- label_namer = None )
2384
+ @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ])
2434
2385
def pie (self , x , explode = None , labels = None , colors = None ,
2435
2386
autopct = None , pctdistance = 0.6 , shadow = False , labeldistance = 1.1 ,
2436
2387
startangle = None , radius = None , counterclock = True ,
@@ -3045,7 +2996,7 @@ def extract_err(err, data):
3045
2996
3046
2997
return errorbar_container # (l0, caplines, barcols)
3047
2998
3048
- @_preprocess_data (label_namer = None )
2999
+ @_preprocess_data ()
3049
3000
def boxplot (self , x , notch = None , sym = None , vert = None , whis = None ,
3050
3001
positions = None , widths = None , patch_artist = None ,
3051
3002
bootstrap = None , usermedians = None , conf_intervals = None ,
@@ -4523,7 +4474,7 @@ def _quiver_units(self, args, kw):
4523
4474
return args
4524
4475
4525
4476
# args can by a combination if X, Y, U, V, C and all should be replaced
4526
- @_preprocess_data (replace_all_args = True , label_namer = None )
4477
+ @_preprocess_data ()
4527
4478
def quiver (self , * args , ** kw ):
4528
4479
# Make sure units are handled for x and y values
4529
4480
args = self ._quiver_units (args , kw )
@@ -4536,13 +4487,12 @@ def quiver(self, *args, **kw):
4536
4487
quiver .__doc__ = mquiver .Quiver .quiver_doc
4537
4488
4538
4489
# args can by either Y or y1,y2,... and all should be replaced
4539
- @_preprocess_data (replace_all_args = True , label_namer = None )
4490
+ @_preprocess_data ()
4540
4491
def stackplot (self , x , * args , ** kwargs ):
4541
4492
return mstack .stackplot (self , x , * args , ** kwargs )
4542
4493
stackplot .__doc__ = mstack .stackplot .__doc__
4543
4494
4544
- @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ],
4545
- label_namer = None )
4495
+ @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ])
4546
4496
def streamplot (self , x , y , u , v , density = 1 , linewidth = None , color = None ,
4547
4497
cmap = None , norm = None , arrowsize = 1 , arrowstyle = '-|>' ,
4548
4498
minlength = 0.1 , transform = None , zorder = None ,
@@ -4567,7 +4517,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4567
4517
streamplot .__doc__ = mstream .streamplot .__doc__
4568
4518
4569
4519
# args can be some combination of X, Y, U, V, C and all should be replaced
4570
- @_preprocess_data (replace_all_args = True , label_namer = None )
4520
+ @_preprocess_data ()
4571
4521
@docstring .dedent_interpd
4572
4522
def barbs (self , * args , ** kw ):
4573
4523
"""
@@ -4581,8 +4531,8 @@ def barbs(self, *args, **kw):
4581
4531
self .autoscale_view ()
4582
4532
return b
4583
4533
4584
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4585
- positional_parameter_names = [ "x" , "y" , "c" ])
4534
+ # Uses a custom implementation of data-kwarg handling in
4535
+ # _process_plot_var_args.
4586
4536
def fill (self , * args , ** kwargs ):
4587
4537
"""
4588
4538
Plot filled polygons.
@@ -4629,8 +4579,7 @@ def fill(self, *args, **kwargs):
4629
4579
self .autoscale_view ()
4630
4580
return patches
4631
4581
4632
- @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ],
4633
- label_namer = None )
4582
+ @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ])
4634
4583
@docstring .dedent_interpd
4635
4584
def fill_between (self , x , y1 , y2 = 0 , where = None , interpolate = False ,
4636
4585
step = None , ** kwargs ):
@@ -4812,8 +4761,7 @@ def get_interp_point(ind):
4812
4761
self .autoscale_view ()
4813
4762
return collection
4814
4763
4815
- @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ],
4816
- label_namer = None )
4764
+ @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ])
4817
4765
@docstring .dedent_interpd
4818
4766
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4819
4767
step = None , interpolate = False , ** kwargs ):
@@ -4995,7 +4943,7 @@ def get_interp_point(ind):
4995
4943
return collection
4996
4944
4997
4945
#### plotting z(x,y): imshow, pcolor and relatives, contour
4998
- @_preprocess_data (label_namer = None )
4946
+ @_preprocess_data ()
4999
4947
def imshow (self , X , cmap = None , norm = None , aspect = None ,
5000
4948
interpolation = None , alpha = None , vmin = None , vmax = None ,
5001
4949
origin = None , extent = None , shape = None , filternorm = 1 ,
@@ -5260,7 +5208,7 @@ def _pcolorargs(funcname, *args, allmatch=False):
5260
5208
C = cbook .safe_masked_invalid (C )
5261
5209
return X , Y , C
5262
5210
5263
- @_preprocess_data (label_namer = None )
5211
+ @_preprocess_data ()
5264
5212
@docstring .dedent_interpd
5265
5213
def pcolor (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5266
5214
vmax = None , ** kwargs ):
@@ -5497,7 +5445,7 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5497
5445
self .autoscale_view ()
5498
5446
return collection
5499
5447
5500
- @_preprocess_data (label_namer = None )
5448
+ @_preprocess_data ()
5501
5449
@docstring .dedent_interpd
5502
5450
def pcolormesh (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5503
5451
vmax = None , shading = 'flat' , antialiased = False , ** kwargs ):
@@ -5710,7 +5658,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5710
5658
self .autoscale_view ()
5711
5659
return collection
5712
5660
5713
- @_preprocess_data (label_namer = None )
5661
+ @_preprocess_data ()
5714
5662
@docstring .dedent_interpd
5715
5663
def pcolorfast (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5716
5664
vmax = None , ** kwargs ):
@@ -6469,7 +6417,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6469
6417
else :
6470
6418
return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6471
6419
6472
- @_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6420
+ @_preprocess_data (replace_names = ["x" , "y" , "weights" ])
6473
6421
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
6474
6422
cmin = None , cmax = None , ** kwargs ):
6475
6423
"""
@@ -6577,7 +6525,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6577
6525
6578
6526
return h , xedges , yedges , pc
6579
6527
6580
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6528
+ @_preprocess_data (replace_names = ["x" ])
6581
6529
@docstring .dedent_interpd
6582
6530
def psd (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
6583
6531
window = None , noverlap = None , pad_to = None ,
@@ -6812,7 +6760,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
6812
6760
else :
6813
6761
return pxy , freqs , line
6814
6762
6815
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6763
+ @_preprocess_data (replace_names = ["x" ])
6816
6764
@docstring .dedent_interpd
6817
6765
def magnitude_spectrum (self , x , Fs = None , Fc = None , window = None ,
6818
6766
pad_to = None , sides = None , scale = None ,
@@ -6915,7 +6863,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
6915
6863
6916
6864
return spec , freqs , lines [0 ]
6917
6865
6918
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6866
+ @_preprocess_data (replace_names = ["x" ])
6919
6867
@docstring .dedent_interpd
6920
6868
def angle_spectrum (self , x , Fs = None , Fc = None , window = None ,
6921
6869
pad_to = None , sides = None , ** kwargs ):
@@ -6997,7 +6945,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
6997
6945
6998
6946
return spec , freqs , lines [0 ]
6999
6947
7000
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6948
+ @_preprocess_data (replace_names = ["x" ])
7001
6949
@docstring .dedent_interpd
7002
6950
def phase_spectrum (self , x , Fs = None , Fc = None , window = None ,
7003
6951
pad_to = None , sides = None , ** kwargs ):
@@ -7078,7 +7026,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
7078
7026
7079
7027
return spec , freqs , lines [0 ]
7080
7028
7081
- @_preprocess_data (replace_names = ["x" , "y" ], label_namer = None )
7029
+ @_preprocess_data (replace_names = ["x" , "y" ])
7082
7030
@docstring .dedent_interpd
7083
7031
def cohere (self , x , y , NFFT = 256 , Fs = 2 , Fc = 0 , detrend = mlab .detrend_none ,
7084
7032
window = mlab .window_hanning , noverlap = 0 , pad_to = None ,
@@ -7143,7 +7091,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7143
7091
7144
7092
return cxy , freqs
7145
7093
7146
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7094
+ @_preprocess_data (replace_names = ["x" ])
7147
7095
@docstring .dedent_interpd
7148
7096
def specgram (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
7149
7097
window = None , noverlap = None ,
@@ -7492,7 +7440,7 @@ def matshow(self, Z, **kwargs):
7492
7440
integer = True ))
7493
7441
return im
7494
7442
7495
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7443
+ @_preprocess_data (replace_names = ["dataset" ])
7496
7444
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
7497
7445
showmeans = False , showextrema = True , showmedians = False ,
7498
7446
points = 100 , bw_method = None ):
0 commit comments