Skip to content

Commit a71d16e

Browse files
committed
ENH: proper arguments for labeled data decorator, part 2
1 parent b38d518 commit a71d16e

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

lib/matplotlib/axes/_axes.py

+41-38
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
981981

982982
return coll
983983

984-
@unpack_labeled_data()
984+
@unpack_labeled_data(replace_names=["x", "ymin", "ymax", "colors"], label_namer="x")
985985
@docstring.dedent_interpd
986986
def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
987987
label='', **kwargs):
@@ -1062,7 +1062,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
10621062

10631063
return coll
10641064

1065-
@unpack_labeled_data()
1065+
@unpack_labeled_data(replace_all_args=False, label_namer=None)
10661066
@docstring.dedent_interpd
10671067
def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
10681068
linelengths=1, linewidths=None, colors=None,
@@ -1245,7 +1245,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12451245
return colls
12461246

12471247
#### Basic plotting
1248-
@unpack_labeled_data()
1248+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
12491249
@docstring.dedent_interpd
12501250
def plot(self, *args, **kwargs):
12511251
"""
@@ -1390,7 +1390,7 @@ def plot(self, *args, **kwargs):
13901390
self.autoscale_view(scalex=scalex, scaley=scaley)
13911391
return lines
13921392

1393-
@unpack_labeled_data()
1393+
@unpack_labeled_data(replace_names=["x", "y"], label_namer="y")
13941394
@docstring.dedent_interpd
13951395
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
13961396
**kwargs):
@@ -1464,7 +1464,7 @@ def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
14641464

14651465
return ret
14661466

1467-
@unpack_labeled_data()
1467+
# @unpack_labeled_data() # let 'plot' do the unpacking..
14681468
@docstring.dedent_interpd
14691469
def loglog(self, *args, **kwargs):
14701470
"""
@@ -1526,7 +1526,7 @@ def loglog(self, *args, **kwargs):
15261526

15271527
return l
15281528

1529-
@unpack_labeled_data()
1529+
# @unpack_labeled_data() # let 'plot' do the unpacking..
15301530
@docstring.dedent_interpd
15311531
def semilogx(self, *args, **kwargs):
15321532
"""
@@ -1579,7 +1579,7 @@ def semilogx(self, *args, **kwargs):
15791579
self._hold = b # restore the hold
15801580
return l
15811581

1582-
@unpack_labeled_data()
1582+
# @unpack_labeled_data() # let 'plot' do the unpacking..
15831583
@docstring.dedent_interpd
15841584
def semilogy(self, *args, **kwargs):
15851585
"""
@@ -1632,7 +1632,7 @@ def semilogy(self, *args, **kwargs):
16321632

16331633
return l
16341634

1635-
@unpack_labeled_data()
1635+
@unpack_labeled_data(replace_names=["x"], label_namer="x")
16361636
@docstring.dedent_interpd
16371637
def acorr(self, x, **kwargs):
16381638
"""
@@ -1694,7 +1694,7 @@ def acorr(self, x, **kwargs):
16941694
"""
16951695
return self.xcorr(x, x, **kwargs)
16961696

1697-
@unpack_labeled_data()
1697+
@unpack_labeled_data(replace_names=["x", "y"], label_namer="y")
16981698
@docstring.dedent_interpd
16991699
def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17001700
usevlines=True, maxlags=10, **kwargs):
@@ -1784,7 +1784,7 @@ def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
17841784

17851785
#### Specialized plotting
17861786

1787-
@unpack_labeled_data()
1787+
@unpack_labeled_data(replace_names=["x", "y"], label_namer="y")
17881788
def step(self, x, y, *args, **kwargs):
17891789
"""
17901790
Make a step plot.
@@ -1822,7 +1822,9 @@ def step(self, x, y, *args, **kwargs):
18221822

18231823
return self.plot(x, y, *args, **kwargs)
18241824

1825-
@unpack_labeled_data()
1825+
@unpack_labeled_data(replace_names=["left", "height", "width", "bottom", "color", "edgecolor",
1826+
"linewidth", "tick_label", "xerr", "yerr", "ecolor"],
1827+
label_namer=None)
18261828
@docstring.dedent_interpd
18271829
def bar(self, left, height, width=0.8, bottom=None, **kwargs):
18281830
"""
@@ -2249,7 +2251,7 @@ def barh(self, bottom, width, height=0.8, left=None, **kwargs):
22492251
bottom=bottom, orientation='horizontal', **kwargs)
22502252
return patches
22512253

2252-
@unpack_labeled_data()
2254+
# @unpack_labeled_data() # not df["name"] getable...
22532255
@docstring.dedent_interpd
22542256
def broken_barh(self, xranges, yrange, **kwargs):
22552257
"""
@@ -2295,7 +2297,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
22952297

22962298
return col
22972299

2298-
@unpack_labeled_data()
2300+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
22992301
def stem(self, *args, **kwargs):
23002302
"""
23012303
Create a stem plot.
@@ -2603,7 +2605,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
26032605
else:
26042606
return slices, texts, autotexts
26052607

2606-
@unpack_labeled_data()
2608+
@unpack_labeled_data(replace_names=["x", "y", "xerr", "yerr",], label_namer="y")
26072609
@docstring.dedent_interpd
26082610
def errorbar(self, x, y, yerr=None, xerr=None,
26092611
fmt='', ecolor=None, elinewidth=None, capsize=None,
@@ -4347,7 +4349,7 @@ def quiverkey(self, *args, **kw):
43474349
return qk
43484350
quiverkey.__doc__ = mquiver.QuiverKey.quiverkey_doc
43494351

4350-
@unpack_labeled_data()
4352+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
43514353
def quiver(self, *args, **kw):
43524354
if not self._hold:
43534355
self.cla()
@@ -4358,12 +4360,12 @@ def quiver(self, *args, **kw):
43584360
return q
43594361
quiver.__doc__ = mquiver.Quiver.quiver_doc
43604362

4361-
@unpack_labeled_data()
4363+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
43624364
def stackplot(self, x, *args, **kwargs):
43634365
return mstack.stackplot(self, x, *args, **kwargs)
43644366
stackplot.__doc__ = mstack.stackplot.__doc__
43654367

4366-
@unpack_labeled_data()
4368+
#@unpack_labeled_data() # doesn't really work, as x and y have different shapes
43674369
def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
43684370
cmap=None, norm=None, arrowsize=1, arrowstyle='-|>',
43694371
minlength=0.1, transform=None, zorder=1, start_points=None):
@@ -4384,7 +4386,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
43844386
return stream_container
43854387
streamplot.__doc__ = mstream.streamplot.__doc__
43864388

4387-
@unpack_labeled_data()
4389+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
43884390
@docstring.dedent_interpd
43894391
def barbs(self, *args, **kw):
43904392
"""
@@ -4401,7 +4403,8 @@ def barbs(self, *args, **kw):
44014403
self.autoscale_view()
44024404
return b
44034405

4404-
@unpack_labeled_data()
4406+
@unpack_labeled_data(replace_names=["x", "y"], label_namer=None,
4407+
positional_parameter_names=["x", "y", "c"])
44054408
@docstring.dedent_interpd
44064409
def fill(self, *args, **kwargs):
44074410
"""
@@ -4453,7 +4456,7 @@ def fill(self, *args, **kwargs):
44534456
self.autoscale_view()
44544457
return patches
44554458

4456-
@unpack_labeled_data()
4459+
@unpack_labeled_data(replace_names=["x", "y1", "y2", "where"], label_namer=None)
44574460
@docstring.dedent_interpd
44584461
def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
44594462
step=None,
@@ -4607,7 +4610,7 @@ def get_interp_point(ind):
46074610
self.autoscale_view()
46084611
return collection
46094612

4610-
@unpack_labeled_data()
4613+
@unpack_labeled_data(replace_names=["y", "x1", "x2", "where"], label_namer=None)
46114614
@docstring.dedent_interpd
46124615
def fill_betweenx(self, y, x1, x2=0, where=None,
46134616
step=None, **kwargs):
@@ -4732,7 +4735,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
47324735
return collection
47334736

47344737
#### plotting z(x,y): imshow, pcolor and relatives, contour
4735-
@unpack_labeled_data()
4738+
#@unpack_labeled_data() # nothing which could be in an DataFrame
47364739
@docstring.dedent_interpd
47374740
def imshow(self, X, cmap=None, norm=None, aspect=None,
47384741
interpolation=None, alpha=None, vmin=None, vmax=None,
@@ -4937,7 +4940,7 @@ def _pcolorargs(funcname, *args, **kw):
49374940
C = C[:Ny - 1, :Nx - 1]
49384941
return X, Y, C
49394942

4940-
@unpack_labeled_data()
4943+
#@unpack_labeled_data() # 2d data can't be df["name"]'ed
49414944
@docstring.dedent_interpd
49424945
def pcolor(self, *args, **kwargs):
49434946
"""
@@ -5214,7 +5217,7 @@ def pcolor(self, *args, **kwargs):
52145217
self.add_collection(collection, autolim=False)
52155218
return collection
52165219

5217-
@unpack_labeled_data()
5220+
#@unpack_labeled_data() # 2d data can't be df["name"]'ed
52185221
@docstring.dedent_interpd
52195222
def pcolormesh(self, *args, **kwargs):
52205223
"""
@@ -5363,7 +5366,7 @@ def pcolormesh(self, *args, **kwargs):
53635366
self.add_collection(collection, autolim=False)
53645367
return collection
53655368

5366-
@unpack_labeled_data()
5369+
#@unpack_labeled_data() #2d data can't be df["name"]'ed
53675370
@docstring.dedent_interpd
53685371
def pcolorfast(self, *args, **kwargs):
53695372
"""
@@ -5551,15 +5554,15 @@ def pcolorfast(self, *args, **kwargs):
55515554
self.autoscale_view(tight=True)
55525555
return ret
55535556

5554-
@unpack_labeled_data()
5557+
#@unpack_labeled_data() # takes 2d data :-(
55555558
def contour(self, *args, **kwargs):
55565559
if not self._hold:
55575560
self.cla()
55585561
kwargs['filled'] = False
55595562
return mcontour.QuadContourSet(self, *args, **kwargs)
55605563
contour.__doc__ = mcontour.QuadContourSet.contour_doc
55615564

5562-
@unpack_labeled_data()
5565+
#@unpack_labeled_data() # takes 2d data :-(
55635566
def contourf(self, *args, **kwargs):
55645567
if not self._hold:
55655568
self.cla()
@@ -5600,7 +5603,7 @@ def table(self, **kwargs):
56005603

56015604
#### Data analysis
56025605

5603-
@unpack_labeled_data()
5606+
@unpack_labeled_data(replace_names=["x"], label_namer="x")
56045607
@docstring.dedent_interpd
56055608
def hist(self, x, bins=10, range=None, normed=False, weights=None,
56065609
cumulative=False, bottom=None, histtype='bar', align='mid',
@@ -6141,7 +6144,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
61416144
else:
61426145
return n, bins, cbook.silent_list('Lists of Patches', patches)
61436146

6144-
@unpack_labeled_data()
6147+
@unpack_labeled_data(replace_names=["x","y", "weights"], label_namer=None)
61456148
@docstring.dedent_interpd
61466149
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
61476150
cmin=None, cmax=None, **kwargs):
@@ -6235,7 +6238,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
62356238

62366239
return h, xedges, yedges, pc
62376240

6238-
@unpack_labeled_data()
6241+
@unpack_labeled_data(replace_names=["x"], label_namer=None)
62396242
@docstring.dedent_interpd
62406243
def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
62416244
window=None, noverlap=None, pad_to=None,
@@ -6360,7 +6363,7 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
63606363
else:
63616364
return pxx, freqs, line
63626365

6363-
@unpack_labeled_data()
6366+
@unpack_labeled_data(replace_names=["x", "y"], label_namer="y")
63646367
@docstring.dedent_interpd
63656368
def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
63666369
window=None, noverlap=None, pad_to=None,
@@ -6472,7 +6475,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
64726475
else:
64736476
return pxy, freqs, line
64746477

6475-
@unpack_labeled_data()
6478+
@unpack_labeled_data(replace_names=["x"], label_namer=None)
64766479
@docstring.dedent_interpd
64776480
def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
64786481
pad_to=None, sides=None, scale=None,
@@ -6572,7 +6575,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
65726575

65736576
return spec, freqs, lines[0]
65746577

6575-
@unpack_labeled_data()
6578+
@unpack_labeled_data(replace_names=["x"], label_namer=None)
65766579
@docstring.dedent_interpd
65776580
def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
65786581
pad_to=None, sides=None, **kwargs):
@@ -6650,7 +6653,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
66506653

66516654
return spec, freqs, lines[0]
66526655

6653-
@unpack_labeled_data()
6656+
@unpack_labeled_data(replace_names=["x"], label_namer=None)
66546657
@docstring.dedent_interpd
66556658
def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
66566659
pad_to=None, sides=None, **kwargs):
@@ -6728,7 +6731,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
67286731

67296732
return spec, freqs, lines[0]
67306733

6731-
@unpack_labeled_data()
6734+
@unpack_labeled_data(replace_names=["x","y"], label_namer=None)
67326735
@docstring.dedent_interpd
67336736
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
67346737
window=mlab.window_hanning, noverlap=0, pad_to=None,
@@ -6796,7 +6799,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
67966799

67976800
return cxy, freqs
67986801

6799-
@unpack_labeled_data()
6802+
@unpack_labeled_data(replace_names=["x"], label_namer=None)
68006803
@docstring.dedent_interpd
68016804
def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
68026805
window=None, noverlap=None,
@@ -7114,7 +7117,7 @@ def matshow(self, Z, **kwargs):
71147117
integer=True))
71157118
return im
71167119

7117-
@unpack_labeled_data()
7120+
@unpack_labeled_data( replace_all_args=True, label_namer=None)
71187121
def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
71197122
showmeans=False, showextrema=True, showmedians=False,
71207123
points=100, bw_method=None):
@@ -7216,7 +7219,7 @@ def _kde_method(X, coords):
72167219
widths=widths, showmeans=showmeans,
72177220
showextrema=showextrema, showmedians=showmedians)
72187221

7219-
@unpack_labeled_data()
7222+
@unpack_labeled_data(replace_all_args=True, label_namer=None)
72207223
def violin(self, vpstats, positions=None, vert=True, widths=0.5,
72217224
showmeans=False, showextrema=True, showmedians=False):
72227225
"""Drawing function for violin plots.

0 commit comments

Comments
 (0)