Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 385b8e3

Browse files
committed
ENH: use the new 'names via function' for @unpack_labeled_data
1 parent c768f0d commit 385b8e3

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,9 +1245,43 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12451245

12461246
return colls
12471247

1248+
def _plot_args_replacer(self, args, data):
1249+
_replacer = []
1250+
remaining = args
1251+
while 1:
1252+
if len(remaining) == 1:
1253+
import warnings
1254+
1255+
msg = "Missing argument: this can happen if a color spec ('c') is in data"
1256+
warnings.warn(msg, RuntimeWarning, stacklevel=3)
1257+
_replacer += ["x"]
1258+
elif len(remaining) == 2:
1259+
_replacer += ["x", "y"]
1260+
elif len(remaining) == 3:
1261+
if remaining[2] in data:
1262+
import warnings
1263+
1264+
msg = "Found a color spec ('c') in data."
1265+
warnings.warn(msg, RuntimeWarning, stacklevel=3)
1266+
_replacer += ["x", "y", "c"]
1267+
1268+
if len(remaining) <= 3:
1269+
return _replacer
1270+
1271+
# More than 3 -> split off the beginning and continue
1272+
if remaining[2] not in data:
1273+
_replacer += ["x", "y", "c"]
1274+
isplit = 3
1275+
else:
1276+
_replacer += ["x", "y"]
1277+
isplit = 2
1278+
remaining = remaining[isplit:]
1279+
12481280
#### Basic plotting
12491281
# The label_naming happens in `matplotlib.axes._base._plot_args`
1250-
@unpack_labeled_data(replace_all_args=True, label_namer=None)
1282+
@unpack_labeled_data(replace_names=["x", "y"],
1283+
positional_parameter_names=_plot_args_replacer,
1284+
label_namer=None)
12511285
@docstring.dedent_interpd
12521286
def plot(self, *args, **kwargs):
12531287
"""
@@ -4378,6 +4412,7 @@ def quiverkey(self, *args, **kw):
43784412
return qk
43794413
quiverkey.__doc__ = mquiver.QuiverKey.quiverkey_doc
43804414

4415+
# args can by a combination if X, Y, U, V, C and all should be replaced
43814416
@unpack_labeled_data(replace_all_args=True, label_namer=None)
43824417
def quiver(self, *args, **kw):
43834418
if not self._hold:
@@ -4389,6 +4424,7 @@ def quiver(self, *args, **kw):
43894424
return q
43904425
quiver.__doc__ = mquiver.Quiver.quiver_doc
43914426

4427+
# args can by either Y or y1,y2,... and all should be replaced
43924428
@unpack_labeled_data(replace_all_args=True, label_namer=None)
43934429
def stackplot(self, x, *args, **kwargs):
43944430
return mstack.stackplot(self, x, *args, **kwargs)
@@ -4416,6 +4452,7 @@ def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None,
44164452
return stream_container
44174453
streamplot.__doc__ = mstream.streamplot.__doc__
44184454

4455+
# args can be some combination of X, Y, U, V, C and all should be replaced
44194456
@unpack_labeled_data(replace_all_args=True, label_namer=None)
44204457
@docstring.dedent_interpd
44214458
def barbs(self, *args, **kw):
@@ -7155,7 +7192,7 @@ def matshow(self, Z, **kwargs):
71557192
integer=True))
71567193
return im
71577194

7158-
@unpack_labeled_data(replace_all_args=True, label_namer=None)
7195+
@unpack_labeled_data(replace_names=["dataset"], label_namer=None)
71597196
def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
71607197
showmeans=False, showextrema=True, showmedians=False,
71617198
points=100, bw_method=None):
@@ -7260,7 +7297,6 @@ def _kde_method(X, coords):
72607297
widths=widths, showmeans=showmeans,
72617298
showextrema=showextrema, showmedians=showmedians)
72627299

7263-
@unpack_labeled_data(replace_all_args=True, label_namer=None)
72647300
def violin(self, vpstats, positions=None, vert=True, widths=0.5,
72657301
showmeans=False, showextrema=True, showmedians=False):
72667302
"""Drawing function for violin plots.

0 commit comments

Comments
 (0)