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 ,
@@ -4519,7 +4470,7 @@ def _quiver_units(self, args, kw):
4519
4470
return args
4520
4471
4521
4472
# args can by a combination if X, Y, U, V, C and all should be replaced
4522
- @_preprocess_data (replace_all_args = True , label_namer = None )
4473
+ @_preprocess_data ()
4523
4474
def quiver (self , * args , ** kw ):
4524
4475
# Make sure units are handled for x and y values
4525
4476
args = self ._quiver_units (args , kw )
@@ -4532,13 +4483,12 @@ def quiver(self, *args, **kw):
4532
4483
quiver .__doc__ = mquiver .Quiver .quiver_doc
4533
4484
4534
4485
# args can by either Y or y1,y2,... and all should be replaced
4535
- @_preprocess_data (replace_all_args = True , label_namer = None )
4486
+ @_preprocess_data ()
4536
4487
def stackplot (self , x , * args , ** kwargs ):
4537
4488
return mstack .stackplot (self , x , * args , ** kwargs )
4538
4489
stackplot .__doc__ = mstack .stackplot .__doc__
4539
4490
4540
- @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ],
4541
- label_namer = None )
4491
+ @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ])
4542
4492
def streamplot (self , x , y , u , v , density = 1 , linewidth = None , color = None ,
4543
4493
cmap = None , norm = None , arrowsize = 1 , arrowstyle = '-|>' ,
4544
4494
minlength = 0.1 , transform = None , zorder = None ,
@@ -4563,7 +4513,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4563
4513
streamplot .__doc__ = mstream .streamplot .__doc__
4564
4514
4565
4515
# args can be some combination of X, Y, U, V, C and all should be replaced
4566
- @_preprocess_data (replace_all_args = True , label_namer = None )
4516
+ @_preprocess_data ()
4567
4517
@docstring .dedent_interpd
4568
4518
def barbs (self , * args , ** kw ):
4569
4519
"""
@@ -4577,8 +4527,8 @@ def barbs(self, *args, **kw):
4577
4527
self .autoscale_view ()
4578
4528
return b
4579
4529
4580
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4581
- positional_parameter_names = [ "x" , "y" , "c" ])
4530
+ # Uses a custom implementation of data-kwarg handling in
4531
+ # _process_plot_var_args.
4582
4532
def fill (self , * args , ** kwargs ):
4583
4533
"""
4584
4534
Plot filled polygons.
@@ -4625,8 +4575,7 @@ def fill(self, *args, **kwargs):
4625
4575
self .autoscale_view ()
4626
4576
return patches
4627
4577
4628
- @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ],
4629
- label_namer = None )
4578
+ @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ])
4630
4579
@docstring .dedent_interpd
4631
4580
def fill_between (self , x , y1 , y2 = 0 , where = None , interpolate = False ,
4632
4581
step = None , ** kwargs ):
@@ -4808,8 +4757,7 @@ def get_interp_point(ind):
4808
4757
self .autoscale_view ()
4809
4758
return collection
4810
4759
4811
- @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ],
4812
- label_namer = None )
4760
+ @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ])
4813
4761
@docstring .dedent_interpd
4814
4762
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4815
4763
step = None , interpolate = False , ** kwargs ):
@@ -4991,7 +4939,7 @@ def get_interp_point(ind):
4991
4939
return collection
4992
4940
4993
4941
#### plotting z(x,y): imshow, pcolor and relatives, contour
4994
- @_preprocess_data (label_namer = None )
4942
+ @_preprocess_data ()
4995
4943
def imshow (self , X , cmap = None , norm = None , aspect = None ,
4996
4944
interpolation = None , alpha = None , vmin = None , vmax = None ,
4997
4945
origin = None , extent = None , shape = None , filternorm = 1 ,
@@ -5256,7 +5204,7 @@ def _pcolorargs(funcname, *args, allmatch=False):
5256
5204
C = cbook .safe_masked_invalid (C )
5257
5205
return X , Y , C
5258
5206
5259
- @_preprocess_data (label_namer = None )
5207
+ @_preprocess_data ()
5260
5208
@docstring .dedent_interpd
5261
5209
def pcolor (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5262
5210
vmax = None , ** kwargs ):
@@ -5493,7 +5441,7 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5493
5441
self .autoscale_view ()
5494
5442
return collection
5495
5443
5496
- @_preprocess_data (label_namer = None )
5444
+ @_preprocess_data ()
5497
5445
@docstring .dedent_interpd
5498
5446
def pcolormesh (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5499
5447
vmax = None , shading = 'flat' , antialiased = False , ** kwargs ):
@@ -5706,7 +5654,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5706
5654
self .autoscale_view ()
5707
5655
return collection
5708
5656
5709
- @_preprocess_data (label_namer = None )
5657
+ @_preprocess_data ()
5710
5658
@docstring .dedent_interpd
5711
5659
def pcolorfast (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5712
5660
vmax = None , ** kwargs ):
@@ -6465,7 +6413,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6465
6413
else :
6466
6414
return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6467
6415
6468
- @_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6416
+ @_preprocess_data (replace_names = ["x" , "y" , "weights" ])
6469
6417
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
6470
6418
cmin = None , cmax = None , ** kwargs ):
6471
6419
"""
@@ -6573,7 +6521,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6573
6521
6574
6522
return h , xedges , yedges , pc
6575
6523
6576
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6524
+ @_preprocess_data (replace_names = ["x" ])
6577
6525
@docstring .dedent_interpd
6578
6526
def psd (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
6579
6527
window = None , noverlap = None , pad_to = None ,
@@ -6808,7 +6756,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
6808
6756
else :
6809
6757
return pxy , freqs , line
6810
6758
6811
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6759
+ @_preprocess_data (replace_names = ["x" ])
6812
6760
@docstring .dedent_interpd
6813
6761
def magnitude_spectrum (self , x , Fs = None , Fc = None , window = None ,
6814
6762
pad_to = None , sides = None , scale = None ,
@@ -6911,7 +6859,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
6911
6859
6912
6860
return spec , freqs , lines [0 ]
6913
6861
6914
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6862
+ @_preprocess_data (replace_names = ["x" ])
6915
6863
@docstring .dedent_interpd
6916
6864
def angle_spectrum (self , x , Fs = None , Fc = None , window = None ,
6917
6865
pad_to = None , sides = None , ** kwargs ):
@@ -6993,7 +6941,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
6993
6941
6994
6942
return spec , freqs , lines [0 ]
6995
6943
6996
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6944
+ @_preprocess_data (replace_names = ["x" ])
6997
6945
@docstring .dedent_interpd
6998
6946
def phase_spectrum (self , x , Fs = None , Fc = None , window = None ,
6999
6947
pad_to = None , sides = None , ** kwargs ):
@@ -7074,7 +7022,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
7074
7022
7075
7023
return spec , freqs , lines [0 ]
7076
7024
7077
- @_preprocess_data (replace_names = ["x" , "y" ], label_namer = None )
7025
+ @_preprocess_data (replace_names = ["x" , "y" ])
7078
7026
@docstring .dedent_interpd
7079
7027
def cohere (self , x , y , NFFT = 256 , Fs = 2 , Fc = 0 , detrend = mlab .detrend_none ,
7080
7028
window = mlab .window_hanning , noverlap = 0 , pad_to = None ,
@@ -7139,7 +7087,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7139
7087
7140
7088
return cxy , freqs
7141
7089
7142
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7090
+ @_preprocess_data (replace_names = ["x" ])
7143
7091
@docstring .dedent_interpd
7144
7092
def specgram (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
7145
7093
window = None , noverlap = None ,
@@ -7488,7 +7436,7 @@ def matshow(self, Z, **kwargs):
7488
7436
integer = True ))
7489
7437
return im
7490
7438
7491
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7439
+ @_preprocess_data (replace_names = ["dataset" ])
7492
7440
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
7493
7441
showmeans = False , showextrema = True , showmedians = False ,
7494
7442
points = 100 , bw_method = None ):
0 commit comments