42
42
rcParams = matplotlib .rcParams
43
43
44
44
45
- def _has_item (data , name ):
46
- """Return whether *data* can be item-accessed with *name*.
47
-
48
- This supports data with a dict-like interface (`in` checks item
49
- availability) and with numpy.arrays.
50
- """
51
- try :
52
- return data .dtype .names is not None and name in data .dtype .names
53
- except AttributeError : # not a numpy array
54
- return name in data
55
-
56
-
57
- def _plot_args_replacer (args , data ):
58
- if len (args ) == 1 :
59
- return ["y" ]
60
- elif len (args ) == 2 :
61
- # this can be two cases: x,y or y,c
62
- if not _has_item (data , args [1 ]):
63
- return ["y" , "c" ]
64
- # it's data, but could be a color code like 'ro' or 'b--'
65
- # -> warn the user in that case...
66
- try :
67
- _process_plot_format (args [1 ])
68
- except ValueError :
69
- pass
70
- else :
71
- cbook ._warn_external (
72
- "Second argument {!r} is ambiguous: could be a color spec but "
73
- "is in data; using as data. Either rename the entry in data "
74
- "or use three arguments to plot." .format (args [1 ]),
75
- RuntimeWarning )
76
- return ["x" , "y" ]
77
- elif len (args ) == 3 :
78
- return ["x" , "y" , "c" ]
79
- else :
80
- raise ValueError ("Using arbitrary long args with data is not "
81
- "supported due to ambiguity of arguments.\n Use "
82
- "multiple plotting calls instead." )
83
-
84
-
85
45
def _make_inset_locator (bounds , trans , parent ):
86
46
"""
87
47
Helper function to locate inset axes, used in
@@ -1153,8 +1113,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
1153
1113
1154
1114
@_preprocess_data (replace_names = ["positions" , "lineoffsets" ,
1155
1115
"linelengths" , "linewidths" ,
1156
- "colors" , "linestyles" ],
1157
- label_namer = None )
1116
+ "colors" , "linestyles" ])
1158
1117
@docstring .dedent_interpd
1159
1118
def eventplot (self , positions , orientation = 'horizontal' , lineoffsets = 1 ,
1160
1119
linelengths = 1 , linewidths = None , colors = None ,
@@ -1370,10 +1329,8 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1370
1329
1371
1330
#### Basic plotting
1372
1331
1373
- # The label_naming happens in `matplotlib.axes._base._plot_args`
1374
- @_preprocess_data (replace_names = ["x" , "y" ],
1375
- positional_parameter_names = _plot_args_replacer ,
1376
- label_namer = None )
1332
+ # Uses a custom implementation of data-kwarg handling in
1333
+ # _process_plot_var_args.
1377
1334
@docstring .dedent_interpd
1378
1335
def plot (self , * args , scalex = True , scaley = True , ** kwargs ):
1379
1336
"""
@@ -1486,7 +1443,6 @@ def plot(self, *args, scalex=True, scaley=True, **kwargs):
1486
1443
You may suppress the warning by adding an empty format string
1487
1444
`plot('n', 'o', '', data=obj)`.
1488
1445
1489
-
1490
1446
Other Parameters
1491
1447
----------------
1492
1448
scalex, scaley : bool, optional, default: True
@@ -1513,13 +1469,11 @@ def plot(self, *args, scalex=True, scaley=True, **kwargs):
1513
1469
lines
1514
1470
A list of `.Line2D` objects representing the plotted data.
1515
1471
1516
-
1517
1472
See Also
1518
1473
--------
1519
1474
scatter : XY scatter plot with markers of varying size and/or color (
1520
1475
sometimes also called bubble chart).
1521
1476
1522
-
1523
1477
Notes
1524
1478
-----
1525
1479
**Format Strings**
@@ -1988,7 +1942,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
1988
1942
1989
1943
#### Specialized plotting
1990
1944
1991
- @_preprocess_data (replace_names = [ "x" , "y" ], label_namer = "y" )
1945
+ # @_preprocess_data() # let 'plot' do the unpacking..
1992
1946
def step (self , x , y , * args , where = 'pre' , ** kwargs ):
1993
1947
"""
1994
1948
Make a step plot.
@@ -2056,15 +2010,7 @@ def step(self, x, y, *args, where='pre', **kwargs):
2056
2010
kwargs ['drawstyle' ] = 'steps-' + where
2057
2011
return self .plot (x , y , * args , ** kwargs )
2058
2012
2059
- @_preprocess_data (replace_names = ["x" , "left" ,
2060
- "height" , "width" ,
2061
- "y" , "bottom" ,
2062
- "color" , "edgecolor" , "linewidth" ,
2063
- "tick_label" , "xerr" , "yerr" ,
2064
- "ecolor" ],
2065
- label_namer = None ,
2066
- replace_all_args = True
2067
- )
2013
+ @_preprocess_data ()
2068
2014
@docstring .dedent_interpd
2069
2015
def bar (self , x , height , width = 0.8 , bottom = None , * , align = "center" ,
2070
2016
** kwargs ):
@@ -2456,7 +2402,7 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
2456
2402
align = align , ** kwargs )
2457
2403
return patches
2458
2404
2459
- @_preprocess_data (label_namer = None )
2405
+ @_preprocess_data ()
2460
2406
@docstring .dedent_interpd
2461
2407
def broken_barh (self , xranges , yrange , ** kwargs ):
2462
2408
"""
@@ -2527,9 +2473,9 @@ def broken_barh(self, xranges, yrange, **kwargs):
2527
2473
2528
2474
return col
2529
2475
2530
- @_preprocess_data (replace_all_args = True , label_namer = None )
2531
- def stem (self , * args , linefmt = None , markerfmt = None , basefmt = None ,
2532
- bottom = 0 , label = None ):
2476
+ @_preprocess_data ()
2477
+ def stem (self , * args , linefmt = None , markerfmt = None , basefmt = None , bottom = 0 ,
2478
+ label = None ):
2533
2479
"""
2534
2480
Create a stem plot.
2535
2481
@@ -2687,8 +2633,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None,
2687
2633
2688
2634
return stem_container
2689
2635
2690
- @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ],
2691
- label_namer = None )
2636
+ @_preprocess_data (replace_names = ["x" , "explode" , "labels" , "colors" ])
2692
2637
def pie (self , x , explode = None , labels = None , colors = None ,
2693
2638
autopct = None , pctdistance = 0.6 , shadow = False , labeldistance = 1.1 ,
2694
2639
startangle = None , radius = None , counterclock = True ,
@@ -3303,7 +3248,7 @@ def extract_err(err, data):
3303
3248
3304
3249
return errorbar_container # (l0, caplines, barcols)
3305
3250
3306
- @_preprocess_data (label_namer = None )
3251
+ @_preprocess_data ()
3307
3252
def boxplot (self , x , notch = None , sym = None , vert = None , whis = None ,
3308
3253
positions = None , widths = None , patch_artist = None ,
3309
3254
bootstrap = None , usermedians = None , conf_intervals = None ,
@@ -4832,7 +4777,7 @@ def _quiver_units(self, args, kw):
4832
4777
return args
4833
4778
4834
4779
# args can by a combination if X, Y, U, V, C and all should be replaced
4835
- @_preprocess_data (replace_all_args = True , label_namer = None )
4780
+ @_preprocess_data ()
4836
4781
def quiver (self , * args , ** kw ):
4837
4782
# Make sure units are handled for x and y values
4838
4783
args = self ._quiver_units (args , kw )
@@ -4845,13 +4790,12 @@ def quiver(self, *args, **kw):
4845
4790
quiver .__doc__ = mquiver .Quiver .quiver_doc
4846
4791
4847
4792
# args can by either Y or y1,y2,... and all should be replaced
4848
- @_preprocess_data (replace_all_args = True , label_namer = None )
4793
+ @_preprocess_data ()
4849
4794
def stackplot (self , x , * args , ** kwargs ):
4850
4795
return mstack .stackplot (self , x , * args , ** kwargs )
4851
4796
stackplot .__doc__ = mstack .stackplot .__doc__
4852
4797
4853
- @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ],
4854
- label_namer = None )
4798
+ @_preprocess_data (replace_names = ["x" , "y" , "u" , "v" , "start_points" ])
4855
4799
def streamplot (self , x , y , u , v , density = 1 , linewidth = None , color = None ,
4856
4800
cmap = None , norm = None , arrowsize = 1 , arrowstyle = '-|>' ,
4857
4801
minlength = 0.1 , transform = None , zorder = None ,
@@ -4876,7 +4820,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
4876
4820
streamplot .__doc__ = mstream .streamplot .__doc__
4877
4821
4878
4822
# args can be some combination of X, Y, U, V, C and all should be replaced
4879
- @_preprocess_data (replace_all_args = True , label_namer = None )
4823
+ @_preprocess_data ()
4880
4824
@docstring .dedent_interpd
4881
4825
def barbs (self , * args , ** kw ):
4882
4826
"""
@@ -4890,8 +4834,8 @@ def barbs(self, *args, **kw):
4890
4834
self .autoscale_view ()
4891
4835
return b
4892
4836
4893
- @ _preprocess_data ( replace_names = [ "x" , "y" ], label_namer = None ,
4894
- positional_parameter_names = [ "x" , "y" , "c" ])
4837
+ # Uses a custom implementation of data-kwarg handling in
4838
+ # _process_plot_var_args.
4895
4839
def fill (self , * args , ** kwargs ):
4896
4840
"""
4897
4841
Plot filled polygons.
@@ -4938,8 +4882,7 @@ def fill(self, *args, **kwargs):
4938
4882
self .autoscale_view ()
4939
4883
return patches
4940
4884
4941
- @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ],
4942
- label_namer = None )
4885
+ @_preprocess_data (replace_names = ["x" , "y1" , "y2" , "where" ])
4943
4886
@docstring .dedent_interpd
4944
4887
def fill_between (self , x , y1 , y2 = 0 , where = None , interpolate = False ,
4945
4888
step = None , ** kwargs ):
@@ -5121,8 +5064,7 @@ def get_interp_point(ind):
5121
5064
self .autoscale_view ()
5122
5065
return collection
5123
5066
5124
- @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ],
5125
- label_namer = None )
5067
+ @_preprocess_data (replace_names = ["y" , "x1" , "x2" , "where" ])
5126
5068
@docstring .dedent_interpd
5127
5069
def fill_betweenx (self , y , x1 , x2 = 0 , where = None ,
5128
5070
step = None , interpolate = False , ** kwargs ):
@@ -5304,7 +5246,7 @@ def get_interp_point(ind):
5304
5246
return collection
5305
5247
5306
5248
#### plotting z(x,y): imshow, pcolor and relatives, contour
5307
- @_preprocess_data (label_namer = None )
5249
+ @_preprocess_data ()
5308
5250
def imshow (self , X , cmap = None , norm = None , aspect = None ,
5309
5251
interpolation = None , alpha = None , vmin = None , vmax = None ,
5310
5252
origin = None , extent = None , shape = None , filternorm = 1 ,
@@ -5571,7 +5513,7 @@ def _pcolorargs(funcname, *args, allmatch=False):
5571
5513
C = cbook .safe_masked_invalid (C )
5572
5514
return X , Y , C
5573
5515
5574
- @_preprocess_data (label_namer = None )
5516
+ @_preprocess_data ()
5575
5517
@docstring .dedent_interpd
5576
5518
def pcolor (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5577
5519
vmax = None , ** kwargs ):
@@ -5808,7 +5750,7 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5808
5750
self .autoscale_view ()
5809
5751
return collection
5810
5752
5811
- @_preprocess_data (label_namer = None )
5753
+ @_preprocess_data ()
5812
5754
@docstring .dedent_interpd
5813
5755
def pcolormesh (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5814
5756
vmax = None , shading = 'flat' , antialiased = False , ** kwargs ):
@@ -6021,7 +5963,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6021
5963
self .autoscale_view ()
6022
5964
return collection
6023
5965
6024
- @_preprocess_data (label_namer = None )
5966
+ @_preprocess_data ()
6025
5967
@docstring .dedent_interpd
6026
5968
def pcolorfast (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
6027
5969
vmax = None , ** kwargs ):
@@ -6785,7 +6727,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6785
6727
else :
6786
6728
return tops , bins , cbook .silent_list ('Lists of Patches' , patches )
6787
6729
6788
- @_preprocess_data (replace_names = ["x" , "y" , "weights" ], label_namer = None )
6730
+ @_preprocess_data (replace_names = ["x" , "y" , "weights" ])
6789
6731
def hist2d (self , x , y , bins = 10 , range = None , normed = False , weights = None ,
6790
6732
cmin = None , cmax = None , ** kwargs ):
6791
6733
"""
@@ -6893,7 +6835,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6893
6835
6894
6836
return h , xedges , yedges , pc
6895
6837
6896
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
6838
+ @_preprocess_data (replace_names = ["x" ])
6897
6839
@docstring .dedent_interpd
6898
6840
def psd (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
6899
6841
window = None , noverlap = None , pad_to = None ,
@@ -7128,7 +7070,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
7128
7070
else :
7129
7071
return pxy , freqs , line
7130
7072
7131
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7073
+ @_preprocess_data (replace_names = ["x" ])
7132
7074
@docstring .dedent_interpd
7133
7075
def magnitude_spectrum (self , x , Fs = None , Fc = None , window = None ,
7134
7076
pad_to = None , sides = None , scale = None ,
@@ -7231,7 +7173,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
7231
7173
7232
7174
return spec , freqs , lines [0 ]
7233
7175
7234
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7176
+ @_preprocess_data (replace_names = ["x" ])
7235
7177
@docstring .dedent_interpd
7236
7178
def angle_spectrum (self , x , Fs = None , Fc = None , window = None ,
7237
7179
pad_to = None , sides = None , ** kwargs ):
@@ -7313,7 +7255,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
7313
7255
7314
7256
return spec , freqs , lines [0 ]
7315
7257
7316
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7258
+ @_preprocess_data (replace_names = ["x" ])
7317
7259
@docstring .dedent_interpd
7318
7260
def phase_spectrum (self , x , Fs = None , Fc = None , window = None ,
7319
7261
pad_to = None , sides = None , ** kwargs ):
@@ -7394,7 +7336,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
7394
7336
7395
7337
return spec , freqs , lines [0 ]
7396
7338
7397
- @_preprocess_data (replace_names = ["x" , "y" ], label_namer = None )
7339
+ @_preprocess_data (replace_names = ["x" , "y" ])
7398
7340
@docstring .dedent_interpd
7399
7341
def cohere (self , x , y , NFFT = 256 , Fs = 2 , Fc = 0 , detrend = mlab .detrend_none ,
7400
7342
window = mlab .window_hanning , noverlap = 0 , pad_to = None ,
@@ -7459,7 +7401,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
7459
7401
7460
7402
return cxy , freqs
7461
7403
7462
- @_preprocess_data (replace_names = ["x" ], label_namer = None )
7404
+ @_preprocess_data (replace_names = ["x" ])
7463
7405
@docstring .dedent_interpd
7464
7406
def specgram (self , x , NFFT = None , Fs = None , Fc = None , detrend = None ,
7465
7407
window = None , noverlap = None ,
@@ -7811,7 +7753,7 @@ def matshow(self, Z, **kwargs):
7811
7753
integer = True ))
7812
7754
return im
7813
7755
7814
- @_preprocess_data (replace_names = ["dataset" ], label_namer = None )
7756
+ @_preprocess_data (replace_names = ["dataset" ])
7815
7757
def violinplot (self , dataset , positions = None , vert = True , widths = 0.5 ,
7816
7758
showmeans = False , showextrema = True , showmedians = False ,
7817
7759
points = 100 , bw_method = None ):
0 commit comments