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
- warnings .warn (
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 , stacklevel = 3 )
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
@@ -2427,8 +2379,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
2427
2379
2428
2380
return stem_container
2429
2381
2430
- @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ],
2431
- label_namer = None )
2382
+ @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ])
2432
2383
def pie (self , x , explode = None , labels = None , colors = None ,
2433
2384
autopct = None , pctdistance = 0.6 , shadow = False , labeldistance = 1.1 ,
2434
2385
startangle = None , radius = None , counterclock = True ,
@@ -3043,7 +2994,7 @@ def extract_err(err, data):
3043
2994
3044
2995
return errorbar_container # (l0, caplines, barcols)
3045
2996
3046
- @_preprocess_data (label_namer = None )
2997
+ @_preprocess_data ()
3047
2998
def boxplot (self , x , notch = None , sym = None , vert = None , whis = None ,
3048
2999
positions = None , widths = None , patch_artist = None ,
3049
3000
bootstrap = None , usermedians = None , conf_intervals = None ,
@@ -4521,7 +4472,7 @@ def _quiver_units(self, args, kw):
4521
4472
return args
4522
4473
4523
4474
# args can by a combination if X, Y, U, V, C and all should be replaced
4524
- @_preprocess_data (replace_all_args = True , label_namer = None )
4475
+ @_preprocess_data ()
4525
4476
def quiver (self , * args , ** kw ):
4526
4477
# Make sure units are handled for x and y values
4527
4478
args = self ._quiver_units (args , kw )
@@ -4534,13 +4485,12 @@ def quiver(self, *args, **kw):
4534
4485
quiver .__doc__ = mquiver .Quiver .quiver_doc
4535
4486
4536
4487
# args can by either Y or y1,y2,... and all should be replaced
4537
- @_preprocess_data (replace_all_args = True , label_namer = None )
4488
+ @_preprocess_data ()
4538
4489
def stackplot (self , x , * args , ** kwargs ):
4539
4490
return mstack .stackplot (self , x , * args , ** kwargs )
4540
4491
stackplot .__doc__ = mstack .stackplot .__doc__
4541
4492
4542
- @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ],
4543
- label_namer = None )
4493
+ @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ])
4544
4494
def streamplot (self , x , y , u , v , density = 1 , linewidth = None , color = None ,
4545
4495
cmap = None , norm = None , arrowsize = 1 , arrowstyle = '-|>' ,
4546
4496
minlength = 0.1 , transform = None , zorder = None ,
@@ -4565,7 +4515,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4565
4515
streamplot .__doc__ = mstream .streamplot .__doc__
4566
4516
4567
4517
# args can be some combination of X, Y, U, V, C and all should be replaced
4568
- @_preprocess_data (replace_all_args = True , label_namer = None )
4518
+ @_preprocess_data ()
4569
4519
@docstring .dedent_interpd
4570
4520
def barbs (self , * args , ** kw ):
4571
4521
"""
@@ -4579,8 +4529,8 @@ def barbs(self, *args, **kw):
4579
4529
self .autoscale_view ()
4580
4530
return b
4581
4531
4582
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4583
- positional_parameter_names = [ "x" , "y" , "c" ])
4532
+ # Uses a custom implementation of data-kwarg handling in
4533
+ # _process_plot_var_args.
4584
4534
def fill (self , * args , ** kwargs ):
4585
4535
"""
4586
4536
Plot filled polygons.
@@ -4627,8 +4577,7 @@ def fill(self, *args, **kwargs):
4627
4577
self .autoscale_view ()
4628
4578
return patches
4629
4579
4630
- @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ],
4631
- label_namer = None )
4580
+ @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ])
4632
4581
@docstring .dedent_interpd
4633
4582
def fill_between (self , x , y1 , y2 = 0 , where = None , interpolate = False ,
4634
4583
step = None , ** kwargs ):
@@ -4810,8 +4759,7 @@ def get_interp_point(ind):
4810
4759
self .autoscale_view ()
4811
4760
return collection
4812
4761
4813
- @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ],
4814
- label_namer = None )
4762
+ @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ])
4815
4763
@docstring .dedent_interpd
4816
4764
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4817
4765
step = None , interpolate = False , ** kwargs ):
@@ -4993,7 +4941,7 @@ def get_interp_point(ind):
4993
4941
return collection
4994
4942
4995
4943
#### plotting z(x,y): imshow, pcolor and relatives, contour
4996
- @_preprocess_data (label_namer = None )
4944
+ @_preprocess_data ()
4997
4945
def imshow (self , X , cmap = None , norm = None , aspect = None ,
4998
4946
interpolation = None , alpha = None , vmin = None , vmax = None ,
4999
4947
origin = None , extent = None , shape = None , filternorm = 1 ,
@@ -5258,7 +5206,7 @@ def _pcolorargs(funcname, *args, allmatch=False):
5258
5206
C = cbook .safe_masked_invalid (C )
5259
5207
return X , Y , C
5260
5208
5261
- @_preprocess_data (label_namer = None )
5209
+ @_preprocess_data ()
5262
5210
@docstring .dedent_interpd
5263
5211
def pcolor (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5264
5212
vmax = None , ** kwargs ):
@@ -5499,7 +5447,7 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5499
5447
self .autoscale_view ()
5500
5448
return collection
5501
5449
5502
- @_preprocess_data (label_namer = None )
5450
+ @_preprocess_data ()
5503
5451
@docstring .dedent_interpd
5504
5452
def pcolormesh (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5505
5453
vmax = None , shading = 'flat' , antialiased = False , ** kwargs ):
@@ -5631,7 +5579,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5631
5579
self .autoscale_view ()
5632
5580
return collection
5633
5581
5634
- @_preprocess_data (label_namer = None )
5582
+ @_preprocess_data ()
5635
5583
@docstring .dedent_interpd
5636
5584
def pcolorfast (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5637
5585
vmax = None , ** kwargs ):
@@ -6372,7 +6320,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6372
6320
else :
6373
6321
return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6374
6322
6375
- @_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6323
+ @_preprocess_data (replace_names = ["x" , "y" , "weights" ])
6376
6324
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
6377
6325
cmin = None , cmax = None , ** kwargs ):
6378
6326
"""
@@ -6480,7 +6428,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6480
6428
6481
6429
return h , xedges , yedges , pc
6482
6430
6483
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6431
+ @_preprocess_data (replace_names = ["x" ])
6484
6432
@docstring .dedent_interpd
6485
6433
def psd (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
6486
6434
window = None , noverlap = None , pad_to = None ,
@@ -6715,7 +6663,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
6715
6663
else :
6716
6664
return pxy , freqs , line
6717
6665
6718
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6666
+ @_preprocess_data (replace_names = ["x" ])
6719
6667
@docstring .dedent_interpd
6720
6668
def magnitude_spectrum (self , x , Fs = None , Fc = None , window = None ,
6721
6669
pad_to = None , sides = None , scale = None ,
@@ -6818,7 +6766,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
6818
6766
6819
6767
return spec , freqs , lines [0 ]
6820
6768
6821
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6769
+ @_preprocess_data (replace_names = ["x" ])
6822
6770
@docstring .dedent_interpd
6823
6771
def angle_spectrum (self , x , Fs = None , Fc = None , window = None ,
6824
6772
pad_to = None , sides = None , ** kwargs ):
@@ -6900,7 +6848,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
6900
6848
6901
6849
return spec , freqs , lines [0 ]
6902
6850
6903
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6851
+ @_preprocess_data (replace_names = ["x" ])
6904
6852
@docstring .dedent_interpd
6905
6853
def phase_spectrum (self , x , Fs = None , Fc = None , window = None ,
6906
6854
pad_to = None , sides = None , ** kwargs ):
@@ -6981,7 +6929,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
6981
6929
6982
6930
return spec , freqs , lines [0 ]
6983
6931
6984
- @_preprocess_data (replace_names = ["x" , "y" ], label_namer = None )
6932
+ @_preprocess_data (replace_names = ["x" , "y" ])
6985
6933
@docstring .dedent_interpd
6986
6934
def cohere (self , x , y , NFFT = 256 , Fs = 2 , Fc = 0 , detrend = mlab .detrend_none ,
6987
6935
window = mlab .window_hanning , noverlap = 0 , pad_to = None ,
@@ -7046,7 +6994,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7046
6994
7047
6995
return cxy , freqs
7048
6996
7049
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6997
+ @_preprocess_data (replace_names = ["x" ])
7050
6998
@docstring .dedent_interpd
7051
6999
def specgram (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
7052
7000
window = None , noverlap = None ,
@@ -7371,7 +7319,7 @@ def matshow(self, Z, **kwargs):
7371
7319
integer = True ))
7372
7320
return im
7373
7321
7374
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7322
+ @_preprocess_data (replace_names = ["dataset" ])
7375
7323
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
7376
7324
showmeans = False , showextrema = True , showmedians = False ,
7377
7325
points = 100 , bw_method = None ):
0 commit comments