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 ,
@@ -1110,10 +1075,8 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1110
1075
1111
1076
#### Basic plotting
1112
1077
1113
- # The label_naming happens in `matplotlib.axes._base._plot_args`
1114
- @_preprocess_data (replace_names = ["x" ,"y" ],
1115
- positional_parameter_names = _plot_args_replacer ,
1116
- label_namer = None )
1078
+ # Uses a custom implementation of data-kwarg handling in
1079
+ # _process_plot_var_args.
1117
1080
@docstring .dedent_interpd
1118
1081
def plot (self ,* args ,** kwargs ):
1119
1082
"""
@@ -1226,7 +1189,6 @@ def plot(self, *args, **kwargs):
1226
1189
You may suppress the warning by adding an empty format string
1227
1190
`plot('n', 'o', '', data=obj)`.
1228
1191
1229
-
1230
1192
Other Parameters
1231
1193
----------------
1232
1194
scalex, scaley : bool, optional, default: True
@@ -1253,13 +1215,11 @@ def plot(self, *args, **kwargs):
1253
1215
lines
1254
1216
A list of `.Line2D` objects representing the plotted data.
1255
1217
1256
-
1257
1218
See Also
1258
1219
--------
1259
1220
scatter : XY scatter plot with markers of variing size and/or color (
1260
1221
sometimes also called bubble chart).
1261
1222
1262
-
1263
1223
Notes
1264
1224
-----
1265
1225
**Format Strings**
@@ -1732,7 +1692,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
1732
1692
1733
1693
#### Specialized plotting
1734
1694
1735
- @_preprocess_data (replace_names = [ "x" , "y" ], label_namer = "y" )
1695
+ # @_preprocess_data() # let 'plot' do the unpacking..
1736
1696
def step (self ,x ,y ,* args ,** kwargs ):
1737
1697
"""
1738
1698
Make a step plot.
@@ -1803,15 +1763,7 @@ def step(self, x, y, *args, **kwargs):
1803
1763
1804
1764
return self .plot (x ,y ,* args ,** kwargs )
1805
1765
1806
- @_preprocess_data (replace_names = ["x" ,"left" ,
1807
- "height" ,"width" ,
1808
- "y" ,"bottom" ,
1809
- "color" ,"edgecolor" ,"linewidth" ,
1810
- "tick_label" ,"xerr" ,"yerr" ,
1811
- "ecolor" ],
1812
- label_namer = None ,
1813
- replace_all_args = True
1814
- )
1766
+ @_preprocess_data ()
1815
1767
@docstring .dedent_interpd
1816
1768
def bar (self ,* args ,** kwargs ):
1817
1769
r"""
@@ -2265,7 +2217,7 @@ def barh(self, *args, **kwargs):
2265
2217
bottom = y ,** kwargs )
2266
2218
return patches
2267
2219
2268
- @_preprocess_data (label_namer = None )
2220
+ @_preprocess_data ()
2269
2221
@docstring .dedent_interpd
2270
2222
def broken_barh (self ,xranges ,yrange ,** kwargs ):
2271
2223
"""
@@ -2336,7 +2288,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
2336
2288
2337
2289
return col
2338
2290
2339
- @_preprocess_data (replace_all_args = True , label_namer = None )
2291
+ @_preprocess_data ()
2340
2292
def stem (self ,* args ,** kwargs ):
2341
2293
"""
2342
2294
Create a stem plot.
@@ -2525,8 +2477,7 @@ def stem(self, *args, **kwargs):
2525
2477
2526
2478
return stem_container
2527
2479
2528
- @_preprocess_data (replace_names = ["x" ,"explode" ,"labels" ,"colors" ],
2529
- label_namer = None )
2480
+ @_preprocess_data (replace_names = ["x" ,"explode" ,"labels" ,"colors" ])
2530
2481
def pie (self ,x ,explode = None ,labels = None ,colors = None ,
2531
2482
autopct = None ,pctdistance = 0.6 ,shadow = False ,labeldistance = 1.1 ,
2532
2483
startangle = None ,radius = None ,counterclock = True ,
@@ -3133,7 +3084,7 @@ def extract_err(err, data):
3133
3084
3134
3085
return errorbar_container # (l0, caplines, barcols)
3135
3086
3136
- @_preprocess_data (label_namer = None )
3087
+ @_preprocess_data ()
3137
3088
def boxplot (self ,x ,notch = None ,sym = None ,vert = None ,whis = None ,
3138
3089
positions = None ,widths = None ,patch_artist = None ,
3139
3090
bootstrap = None ,usermedians = None ,conf_intervals = None ,
@@ -4612,7 +4563,7 @@ def _quiver_units(self, args, kw):
4612
4563
return args
4613
4564
4614
4565
# args can by a combination if X, Y, U, V, C and all should be replaced
4615
- @_preprocess_data (replace_all_args = True , label_namer = None )
4566
+ @_preprocess_data ()
4616
4567
def quiver (self ,* args ,** kw ):
4617
4568
# Make sure units are handled for x and y values
4618
4569
args = self ._quiver_units (args ,kw )
@@ -4625,13 +4576,12 @@ def quiver(self, *args, **kw):
4625
4576
quiver .__doc__ = mquiver .Quiver .quiver_doc
4626
4577
4627
4578
# args can by either Y or y1,y2,... and all should be replaced
4628
- @_preprocess_data (replace_all_args = True , label_namer = None )
4579
+ @_preprocess_data ()
4629
4580
def stackplot (self ,x ,* args ,** kwargs ):
4630
4581
return mstack .stackplot (self ,x ,* args ,** kwargs )
4631
4582
stackplot .__doc__ = mstack .stackplot .__doc__
4632
4583
4633
- @_preprocess_data (replace_names = ["x" ,"y" ,"u" ,"v" ,"start_points" ],
4634
- label_namer = None )
4584
+ @_preprocess_data (replace_names = ["x" ,"y" ,"u" ,"v" ,"start_points" ])
4635
4585
def streamplot (self ,x ,y ,u ,v ,density = 1 ,linewidth = None ,color = None ,
4636
4586
cmap = None ,norm = None ,arrowsize = 1 ,arrowstyle = '-|>' ,
4637
4587
minlength = 0.1 ,transform = None ,zorder = None ,
@@ -4656,7 +4606,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4656
4606
streamplot .__doc__ = mstream .streamplot .__doc__
4657
4607
4658
4608
# args can be some combination of X, Y, U, V, C and all should be replaced
4659
- @_preprocess_data (replace_all_args = True , label_namer = None )
4609
+ @_preprocess_data ()
4660
4610
@docstring .dedent_interpd
4661
4611
def barbs (self ,* args ,** kw ):
4662
4612
"""
@@ -4670,8 +4620,8 @@ def barbs(self, *args, **kw):
4670
4620
self .autoscale_view ()
4671
4621
return b
4672
4622
4673
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4674
- positional_parameter_names = [ "x" , "y" , "c" ])
4623
+ # Uses a custom implementation of data-kwarg handling in
4624
+ # _process_plot_var_args.
4675
4625
def fill (self ,* args ,** kwargs ):
4676
4626
"""
4677
4627
Plot filled polygons.
@@ -4718,8 +4668,7 @@ def fill(self, *args, **kwargs):
4718
4668
self .autoscale_view ()
4719
4669
return patches
4720
4670
4721
- @_preprocess_data (replace_names = ["x" ,"y1" ,"y2" ,"where" ],
4722
- label_namer = None )
4671
+ @_preprocess_data (replace_names = ["x" ,"y1" ,"y2" ,"where" ])
4723
4672
@docstring .dedent_interpd
4724
4673
def fill_between (self ,x ,y1 ,y2 = 0 ,where = None ,interpolate = False ,
4725
4674
step = None ,** kwargs ):
@@ -4901,8 +4850,7 @@ def get_interp_point(ind):
4901
4850
self .autoscale_view ()
4902
4851
return collection
4903
4852
4904
- @_preprocess_data (replace_names = ["y" ,"x1" ,"x2" ,"where" ],
4905
- label_namer = None )
4853
+ @_preprocess_data (replace_names = ["y" ,"x1" ,"x2" ,"where" ])
4906
4854
@docstring .dedent_interpd
4907
4855
def fill_betweenx (self ,y ,x1 ,x2 = 0 ,where = None ,
4908
4856
step = None ,interpolate = False ,** kwargs ):
@@ -5084,7 +5032,7 @@ def get_interp_point(ind):
5084
5032
return collection
5085
5033
5086
5034
#### plotting z(x,y): imshow, pcolor and relatives, contour
5087
- @_preprocess_data (label_namer = None )
5035
+ @_preprocess_data ()
5088
5036
def imshow (self ,X ,cmap = None ,norm = None ,aspect = None ,
5089
5037
interpolation = None ,alpha = None ,vmin = None ,vmax = None ,
5090
5038
origin = None ,extent = None ,shape = None ,filternorm = 1 ,
@@ -5313,7 +5261,7 @@ def _pcolorargs(funcname, *args, **kw):
5313
5261
C = cbook .safe_masked_invalid (C )
5314
5262
return X ,Y ,C
5315
5263
5316
- @_preprocess_data (label_namer = None )
5264
+ @_preprocess_data ()
5317
5265
@docstring .dedent_interpd
5318
5266
def pcolor (self ,* args ,** kwargs ):
5319
5267
"""
@@ -5559,7 +5507,7 @@ def pcolor(self, *args, **kwargs):
5559
5507
self .autoscale_view ()
5560
5508
return collection
5561
5509
5562
- @_preprocess_data (label_namer = None )
5510
+ @_preprocess_data ()
5563
5511
@docstring .dedent_interpd
5564
5512
def pcolormesh (self ,* args ,** kwargs ):
5565
5513
"""
@@ -5696,7 +5644,7 @@ def pcolormesh(self, *args, **kwargs):
5696
5644
self .autoscale_view ()
5697
5645
return collection
5698
5646
5699
- @_preprocess_data (label_namer = None )
5647
+ @_preprocess_data ()
5700
5648
@docstring .dedent_interpd
5701
5649
def pcolorfast (self ,* args ,** kwargs ):
5702
5650
"""
@@ -6441,7 +6389,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6441
6389
else :
6442
6390
return tops ,bins ,cbook .silent_list ('Lists of Patches' ,patches )
6443
6391
6444
- @_preprocess_data (replace_names = ["x" ,"y" ,"weights" ], label_namer = None )
6392
+ @_preprocess_data (replace_names = ["x" ,"y" ,"weights" ])
6445
6393
def hist2d (self ,x ,y ,bins = 10 ,range = None ,normed = False ,weights = None ,
6446
6394
cmin = None ,cmax = None ,** kwargs ):
6447
6395
"""
@@ -6548,7 +6496,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6548
6496
6549
6497
return h ,xedges ,yedges ,pc
6550
6498
6551
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6499
+ @_preprocess_data (replace_names = ["x" ])
6552
6500
@docstring .dedent_interpd
6553
6501
def psd (self ,x ,NFFT = None ,Fs = None ,Fc = None ,detrend = None ,
6554
6502
window = None ,noverlap = None ,pad_to = None ,
@@ -6783,7 +6731,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
6783
6731
else :
6784
6732
return pxy ,freqs ,line
6785
6733
6786
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6734
+ @_preprocess_data (replace_names = ["x" ])
6787
6735
@docstring .dedent_interpd
6788
6736
def magnitude_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
6789
6737
pad_to = None ,sides = None ,scale = None ,
@@ -6886,7 +6834,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
6886
6834
6887
6835
return spec ,freqs ,lines [0 ]
6888
6836
6889
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6837
+ @_preprocess_data (replace_names = ["x" ])
6890
6838
@docstring .dedent_interpd
6891
6839
def angle_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
6892
6840
pad_to = None ,sides = None ,** kwargs ):
@@ -6968,7 +6916,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
6968
6916
6969
6917
return spec ,freqs ,lines [0 ]
6970
6918
6971
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6919
+ @_preprocess_data (replace_names = ["x" ])
6972
6920
@docstring .dedent_interpd
6973
6921
def phase_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
6974
6922
pad_to = None ,sides = None ,** kwargs ):
@@ -7049,7 +6997,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
7049
6997
7050
6998
return spec ,freqs ,lines [0 ]
7051
6999
7052
- @_preprocess_data (replace_names = ["x" ,"y" ], label_namer = None )
7000
+ @_preprocess_data (replace_names = ["x" ,"y" ])
7053
7001
@docstring .dedent_interpd
7054
7002
def cohere (self ,x ,y ,NFFT = 256 ,Fs = 2 ,Fc = 0 ,detrend = mlab .detrend_none ,
7055
7003
window = mlab .window_hanning ,noverlap = 0 ,pad_to = None ,
@@ -7114,7 +7062,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7114
7062
7115
7063
return cxy ,freqs
7116
7064
7117
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7065
+ @_preprocess_data (replace_names = ["x" ])
7118
7066
@docstring .dedent_interpd
7119
7067
def specgram (self ,x ,NFFT = None ,Fs = None ,Fc = None ,detrend = None ,
7120
7068
window = None ,noverlap = None ,
@@ -7430,7 +7378,7 @@ def matshow(self, Z, **kwargs):
7430
7378
integer = True ))
7431
7379
return im
7432
7380
7433
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7381
+ @_preprocess_data (replace_names = ["dataset" ])
7434
7382
def violinplot (self ,dataset ,positions = None ,vert = True ,widths = 0.5 ,
7435
7383
showmeans = False ,showextrema = True ,showmedians = False ,
7436
7384
points = 100 ,bw_method = None ):