4444rcParams = matplotlib .rcParams
4545
4646
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-
8147# The axes module contains all the wrappers to plotting functions.
8248# All the other methods should go in the _AxesBase class.
8349
@@ -894,8 +860,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
894860
895861@_preprocess_data (replace_names = ["positions" ,"lineoffsets" ,
896862"linelengths" ,"linewidths" ,
897- "colors" ,"linestyles" ],
898- label_namer = None )
863+ "colors" ,"linestyles" ])
899864@docstring .dedent_interpd
900865def eventplot (self ,positions ,orientation = 'horizontal' ,lineoffsets = 1 ,
901866linelengths = 1 ,linewidths = None ,colors = None ,
@@ -1110,10 +1075,8 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
11101075
11111076#### Basic plotting
11121077
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.
11171080@docstring .dedent_interpd
11181081def plot (self ,* args ,** kwargs ):
11191082"""
@@ -1226,7 +1189,6 @@ def plot(self, *args, **kwargs):
12261189 You may suppress the warning by adding an empty format string
12271190 `plot('n', 'o', '', data=obj)`.
12281191
1229-
12301192 Other Parameters
12311193 ----------------
12321194 scalex, scaley : bool, optional, default: True
@@ -1253,13 +1215,11 @@ def plot(self, *args, **kwargs):
12531215 lines
12541216 A list of `.Line2D` objects representing the plotted data.
12551217
1256-
12571218 See Also
12581219 --------
12591220 scatter : XY scatter plot with markers of variing size and/or color (
12601221 sometimes also called bubble chart).
12611222
1262-
12631223 Notes
12641224 -----
12651225 **Format Strings**
@@ -1732,7 +1692,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17321692
17331693#### Specialized plotting
17341694
1735- @_preprocess_data (replace_names = [ "x" , "y" ], label_namer = "y" )
1695+ # @_preprocess_data() # let 'plot' do the unpacking..
17361696def step (self ,x ,y ,* args ,** kwargs ):
17371697"""
17381698 Make a step plot.
@@ -1803,15 +1763,7 @@ def step(self, x, y, *args, **kwargs):
18031763
18041764return self .plot (x ,y ,* args ,** kwargs )
18051765
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 ()
18151767@docstring .dedent_interpd
18161768def bar (self ,* args ,** kwargs ):
18171769r"""
@@ -2265,7 +2217,7 @@ def barh(self, *args, **kwargs):
22652217bottom = y ,** kwargs )
22662218return patches
22672219
2268- @_preprocess_data (label_namer = None )
2220+ @_preprocess_data ()
22692221@docstring .dedent_interpd
22702222def broken_barh (self ,xranges ,yrange ,** kwargs ):
22712223"""
@@ -2336,7 +2288,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
23362288
23372289return col
23382290
2339- @_preprocess_data (replace_all_args = True , label_namer = None )
2291+ @_preprocess_data ()
23402292def stem (self ,* args ,** kwargs ):
23412293"""
23422294 Create a stem plot.
@@ -2525,8 +2477,7 @@ def stem(self, *args, **kwargs):
25252477
25262478return stem_container
25272479
2528- @_preprocess_data (replace_names = ["x" ,"explode" ,"labels" ,"colors" ],
2529- label_namer = None )
2480+ @_preprocess_data (replace_names = ["x" ,"explode" ,"labels" ,"colors" ])
25302481def pie (self ,x ,explode = None ,labels = None ,colors = None ,
25312482autopct = None ,pctdistance = 0.6 ,shadow = False ,labeldistance = 1.1 ,
25322483startangle = None ,radius = None ,counterclock = True ,
@@ -3133,7 +3084,7 @@ def extract_err(err, data):
31333084
31343085return errorbar_container # (l0, caplines, barcols)
31353086
3136- @_preprocess_data (label_namer = None )
3087+ @_preprocess_data ()
31373088def boxplot (self ,x ,notch = None ,sym = None ,vert = None ,whis = None ,
31383089positions = None ,widths = None ,patch_artist = None ,
31393090bootstrap = None ,usermedians = None ,conf_intervals = None ,
@@ -4612,7 +4563,7 @@ def _quiver_units(self, args, kw):
46124563return args
46134564
46144565# 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 ()
46164567def quiver (self ,* args ,** kw ):
46174568# Make sure units are handled for x and y values
46184569args = self ._quiver_units (args ,kw )
@@ -4625,13 +4576,12 @@ def quiver(self, *args, **kw):
46254576quiver .__doc__ = mquiver .Quiver .quiver_doc
46264577
46274578# 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 ()
46294580def stackplot (self ,x ,* args ,** kwargs ):
46304581return mstack .stackplot (self ,x ,* args ,** kwargs )
46314582stackplot .__doc__ = mstack .stackplot .__doc__
46324583
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" ])
46354585def streamplot (self ,x ,y ,u ,v ,density = 1 ,linewidth = None ,color = None ,
46364586cmap = None ,norm = None ,arrowsize = 1 ,arrowstyle = '-|>' ,
46374587minlength = 0.1 ,transform = None ,zorder = None ,
@@ -4656,7 +4606,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
46564606streamplot .__doc__ = mstream .streamplot .__doc__
46574607
46584608# 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 ()
46604610@docstring .dedent_interpd
46614611def barbs (self ,* args ,** kw ):
46624612"""
@@ -4670,8 +4620,8 @@ def barbs(self, *args, **kw):
46704620self .autoscale_view ()
46714621return b
46724622
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.
46754625def fill (self ,* args ,** kwargs ):
46764626"""
46774627 Plot filled polygons.
@@ -4718,8 +4668,7 @@ def fill(self, *args, **kwargs):
47184668self .autoscale_view ()
47194669return patches
47204670
4721- @_preprocess_data (replace_names = ["x" ,"y1" ,"y2" ,"where" ],
4722- label_namer = None )
4671+ @_preprocess_data (replace_names = ["x" ,"y1" ,"y2" ,"where" ])
47234672@docstring .dedent_interpd
47244673def fill_between (self ,x ,y1 ,y2 = 0 ,where = None ,interpolate = False ,
47254674step = None ,** kwargs ):
@@ -4901,8 +4850,7 @@ def get_interp_point(ind):
49014850self .autoscale_view ()
49024851return collection
49034852
4904- @_preprocess_data (replace_names = ["y" ,"x1" ,"x2" ,"where" ],
4905- label_namer = None )
4853+ @_preprocess_data (replace_names = ["y" ,"x1" ,"x2" ,"where" ])
49064854@docstring .dedent_interpd
49074855def fill_betweenx (self ,y ,x1 ,x2 = 0 ,where = None ,
49084856step = None ,interpolate = False ,** kwargs ):
@@ -5084,7 +5032,7 @@ def get_interp_point(ind):
50845032return collection
50855033
50865034#### plotting z(x,y): imshow, pcolor and relatives, contour
5087- @_preprocess_data (label_namer = None )
5035+ @_preprocess_data ()
50885036def imshow (self ,X ,cmap = None ,norm = None ,aspect = None ,
50895037interpolation = None ,alpha = None ,vmin = None ,vmax = None ,
50905038origin = None ,extent = None ,shape = None ,filternorm = 1 ,
@@ -5313,7 +5261,7 @@ def _pcolorargs(funcname, *args, **kw):
53135261C = cbook .safe_masked_invalid (C )
53145262return X ,Y ,C
53155263
5316- @_preprocess_data (label_namer = None )
5264+ @_preprocess_data ()
53175265@docstring .dedent_interpd
53185266def pcolor (self ,* args ,** kwargs ):
53195267"""
@@ -5559,7 +5507,7 @@ def pcolor(self, *args, **kwargs):
55595507self .autoscale_view ()
55605508return collection
55615509
5562- @_preprocess_data (label_namer = None )
5510+ @_preprocess_data ()
55635511@docstring .dedent_interpd
55645512def pcolormesh (self ,* args ,** kwargs ):
55655513"""
@@ -5696,7 +5644,7 @@ def pcolormesh(self, *args, **kwargs):
56965644self .autoscale_view ()
56975645return collection
56985646
5699- @_preprocess_data (label_namer = None )
5647+ @_preprocess_data ()
57005648@docstring .dedent_interpd
57015649def pcolorfast (self ,* args ,** kwargs ):
57025650"""
@@ -6441,7 +6389,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64416389else :
64426390return tops ,bins ,cbook .silent_list ('Lists of Patches' ,patches )
64436391
6444- @_preprocess_data (replace_names = ["x" ,"y" ,"weights" ], label_namer = None )
6392+ @_preprocess_data (replace_names = ["x" ,"y" ,"weights" ])
64456393def hist2d (self ,x ,y ,bins = 10 ,range = None ,normed = False ,weights = None ,
64466394cmin = None ,cmax = None ,** kwargs ):
64476395"""
@@ -6548,7 +6496,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
65486496
65496497return h ,xedges ,yedges ,pc
65506498
6551- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6499+ @_preprocess_data (replace_names = ["x" ])
65526500@docstring .dedent_interpd
65536501def psd (self ,x ,NFFT = None ,Fs = None ,Fc = None ,detrend = None ,
65546502window = None ,noverlap = None ,pad_to = None ,
@@ -6783,7 +6731,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
67836731else :
67846732return pxy ,freqs ,line
67856733
6786- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6734+ @_preprocess_data (replace_names = ["x" ])
67876735@docstring .dedent_interpd
67886736def magnitude_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
67896737pad_to = None ,sides = None ,scale = None ,
@@ -6886,7 +6834,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
68866834
68876835return spec ,freqs ,lines [0 ]
68886836
6889- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6837+ @_preprocess_data (replace_names = ["x" ])
68906838@docstring .dedent_interpd
68916839def angle_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
68926840pad_to = None ,sides = None ,** kwargs ):
@@ -6968,7 +6916,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
69686916
69696917return spec ,freqs ,lines [0 ]
69706918
6971- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6919+ @_preprocess_data (replace_names = ["x" ])
69726920@docstring .dedent_interpd
69736921def phase_spectrum (self ,x ,Fs = None ,Fc = None ,window = None ,
69746922pad_to = None ,sides = None ,** kwargs ):
@@ -7049,7 +6997,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
70496997
70506998return spec ,freqs ,lines [0 ]
70516999
7052- @_preprocess_data (replace_names = ["x" ,"y" ], label_namer = None )
7000+ @_preprocess_data (replace_names = ["x" ,"y" ])
70537001@docstring .dedent_interpd
70547002def cohere (self ,x ,y ,NFFT = 256 ,Fs = 2 ,Fc = 0 ,detrend = mlab .detrend_none ,
70557003window = 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,
71147062
71157063return cxy ,freqs
71167064
7117- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7065+ @_preprocess_data (replace_names = ["x" ])
71187066@docstring .dedent_interpd
71197067def specgram (self ,x ,NFFT = None ,Fs = None ,Fc = None ,detrend = None ,
71207068window = None ,noverlap = None ,
@@ -7430,7 +7378,7 @@ def matshow(self, Z, **kwargs):
74307378integer = True ))
74317379return im
74327380
7433- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7381+ @_preprocess_data (replace_names = ["dataset" ])
74347382def violinplot (self ,dataset ,positions = None ,vert = True ,widths = 0.5 ,
74357383showmeans = False ,showextrema = True ,showmedians = False ,
74367384points = 100 ,bw_method = None ):