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 ,
@@ -3136,7 +3087,7 @@ def extract_err(err, data):
3136
3087
3137
3088
return errorbar_container # (l0, caplines, barcols)
3138
3089
3139
- @_preprocess_data (label_namer = None )
3090
+ @_preprocess_data ()
3140
3091
def boxplot (self , x , notch = None , sym = None , vert = None , whis = None ,
3141
3092
positions = None , widths = None , patch_artist = None ,
3142
3093
bootstrap = None , usermedians = None , conf_intervals = None ,
@@ -4614,7 +4565,7 @@ def _quiver_units(self, args, kw):
4614
4565
return args
4615
4566
4616
4567
# args can by a combination if X, Y, U, V, C and all should be replaced
4617
- @_preprocess_data (replace_all_args = True , label_namer = None )
4568
+ @_preprocess_data ()
4618
4569
def quiver (self , * args , ** kw ):
4619
4570
# Make sure units are handled for x and y values
4620
4571
args = self ._quiver_units (args , kw )
@@ -4627,13 +4578,12 @@ def quiver(self, *args, **kw):
4627
4578
quiver .__doc__ = mquiver .Quiver .quiver_doc
4628
4579
4629
4580
# args can by either Y or y1,y2,... and all should be replaced
4630
- @_preprocess_dat
2851
a (replace_all_args = True , label_namer = None )
4581
+ @_preprocess_data ()
4631
4582
def stackplot (self , x , * args , ** kwargs ):
4632
4583
return mstack .stackplot (self , x , * args , ** kwargs )
4633
4584
stackplot .__doc__ = mstack .stackplot .__doc__
4634
4585
4635
- @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ],
4636
- label_namer = None )
4586
+ @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ])
4637
4587
def streamplot (self , x , y , u , v , density = 1 , linewidth = None , color = None ,
4638
4588
cmap = None , norm = None , arrowsize = 1 , arrowstyle = '-|>' ,
4639
4589
minlength = 0.1 , transform = None , zorder = None ,
@@ -4658,7 +4608,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4658
4608
streamplot .__doc__ = mstream .streamplot .__doc__
4659
4609
4660
4610
# args can be some combination of X, Y, U, V, C and all should be replaced
4661
- @_preprocess_data (replace_all_args = True , label_namer = None )
4611
+ @_preprocess_data ()
4662
4612
@docstring .dedent_interpd
4663
4613
def barbs (self , * args , ** kw ):
4664
4614
"""
@@ -4672,8 +4622,8 @@ def barbs(self, *args, **kw):
4672
4622
self .autoscale_view ()
4673
4623
return b
4674
4624
4675
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4676
- positional_parameter_names = [ "x" , "y" , "c" ])
4625
+ # Uses a custom implementation of data-kwarg handling in
4626
+ # _process_plot_var_args.
4677
4627
def fill (self , * args , ** kwargs ):
4678
4628
"""
4679
4629
Plot filled polygons.
@@ -4720,8 +4670,7 @@ def fill(self, *args, **kwargs):
4720
4670
self .autoscale_view ()
4721
4671
return patches
4722
4672
4723
- @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ],
4724
- label_namer = None )
4673
+ @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ])
4725
4674
@docstring .dedent_interpd
4726
4675
def fill_between (self , x , y1 , y2 = 0 , where = None , interpolate = False ,
4727
4676
step = None , ** kwargs ):
@@ -4903,8 +4852,7 @@ def get_interp_point(ind):
4903
4852
self .autoscale_view ()
4904
4853
return collection
4905
4854
4906
- @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ],
4907
- label_namer = None )
4855
+ @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ])
4908
4856
@docstring .dedent_interpd
4909
4857
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
4910
4858
step = None , interpolate = False , ** kwargs ):
@@ -5086,7 +5034,7 @@ def get_interp_point(ind):
5086
5034
return collection
5087
5035
5088
5036
#### plotting z(x,y): imshow, pcolor and relatives, contour
5089
- @_preprocess_data (label_namer = None )
5037
+ @_preprocess_data ()
5090
5038
def imshow (self , X , cmap = None , norm = None , aspect = None ,
5091
5039
interpolation = None , alpha = None , vmin = None , vmax = None ,
5092
5040
origin = None , extent = None , shape = None , filternorm = 1 ,
@@ -5315,7 +5263,7 @@ def _pcolorargs(funcname, *args, **kw):
5315
5263
C = cbook .safe_masked_invalid (C )
5316
5264
return X , Y , C
5317
5265
5318
- @_preprocess_data (label_namer = None )
5266
+ @_preprocess_data ()
5319
5267
@docstring .dedent_interpd
5320
5268
def pcolor (self , * args , ** kwargs ):
5321
5269
"""
@@ -5561,7 +5509,7 @@ def pcolor(self, *args, **kwargs):
5561
5509
self .autoscale_view ()
5562
5510
return collection
5563
5511
5564
- @_preprocess_data (label_namer = None )
5512
+ @_preprocess_data ()
5565
5513
@docstring .dedent_interpd
5566
5514
def pcolormesh (self , * args , ** kwargs ):
5567
5515
"""
@@ -5698,7 +5646,7 @@ def pcolormesh(self, *args, **kwargs):
5698
5646
self .autoscale_view ()
5699
5647
return collection
5700
5648
5701
- @_preprocess_data (label_namer = None )
5649
+ @_preprocess_data ()
5702
5650
@docstring .dedent_interpd
5703
5651
def pcolorfast (self , * args , ** kwargs ):
5704
5652
"""
@@ -6443,7 +6391,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6443
6391
else :
6444
6392
return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6445
6393
6446
- @_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6394
+ @_preprocess_data (replace_names = ["x" , "y" , "weights" ])
6447
6395
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
6448
6396
cmin = None , cmax = None , ** kwargs ):
6449
6397
"""
@@ -6550,7 +6498,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6550
6498
6551
6499
return h , xedges , yedges , pc
6552
6500
6553
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6501
+ @_preprocess_data (replace_names = ["x" ])
6554
6502
@docstring .dedent_interpd
6555
6503
def psd (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
6556
6504
window = None , noverlap = None , pad_to = None ,
@@ -6785,7 +6733,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
6785
6733
else :
6786
6734
return pxy , freqs , line
6787
6735
6788
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6736
+ @_preprocess_data (replace_names = ["x" ])
6789
6737
@docstring .dedent_interpd
6790
6738
def magnitude_spectrum (self , x , Fs = None , Fc = None , window = None ,
6791
6739
pad_to = None , sides = None , scale = None ,
@@ -6888,7 +6836,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
6888
6836
6889
6837
return spec , freqs , lines [0 ]
6890
6838
6891
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6839
+ @_preprocess_data (replace_names = ["x" ])
6892
6840
@docstring .dedent_interpd
6893
6841
def angle_spectrum (self , x , Fs = None , Fc = None , window = None ,
6894
6842
pad_to = None , sides = None , ** kwargs ):
@@ -6970,7 +6918,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
6970
6918
6971
6919
return spec , freqs , lines [0 ]
6972
6920
6973
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6921
+ @_preprocess_data (replace_names = ["x" ])
6974
6922
@docstring .dedent_interpd
EDF2
td>6975
6923
def phase_spectrum (self , x , Fs = None , Fc = None , window = None ,
6976
6924
pad_to = None , sides = None , ** kwargs ):
@@ -7051,7 +6999,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
7051
6999
7052
7000
return spec , freqs , lines [0 ]
7053
7001
7054
- @_preprocess_data (replace_names = ["x" , "y" ], label_namer = None )
7002
+ @_preprocess_data (replace_names = ["x" , "y" ])
7055
7003
@docstring .dedent_interpd
7056
7004
def cohere (self , x , y , NFFT = 256 , Fs = 2 , Fc = 0 , detrend = mlab .detrend_none ,
7057
7005
window = mlab .window_hanning , noverlap = 0 , pad_to = None ,
@@ -7116,7 +7064,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7116
7064
7117
7065
return cxy , freqs
7118
7066
7119
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7067
+ @_preprocess_data (replace_names = ["x" ])
7120
7068
@docstring .dedent_interpd
7121
7069
def specgram (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
7122
7070
window = None , noverlap = None ,
@@ -7441,7 +7389,7 @@ def matshow(self, Z, **kwargs):
7441
7389
integer = True ))
7442
7390
return im
7443
7391
7444
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7392
+ @_preprocess_data (replace_names = ["dataset" ])
7445
7393
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
7446
7394
showmeans = False , showextrema = True , showmedians = False ,
7447
7395
points = 100 , bw_method = None ):
0 commit comments