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

Skip to content

Commit b09370e

Browse files
tacaswelljankatins
authored andcommitted
WIP: review work
should split this up into smaller commits
1 parent ecc91e5 commit b09370e

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

lib/matplotlib/__init__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
import functools
120120
# cbook must import matplotlib only within function
121121
# definitions, so it is safe to import from it here.
122-
from matplotlib.cbook import is_string_like, mplDeprecation, dedent
122+
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
123123
from matplotlib.compat import subprocess
124124
from matplotlib.rcsetup import (defaultParams,
125125
validate_backend,
@@ -1646,9 +1646,9 @@ def param(func):
16461646
# arguments
16471647
label_pos = 9999 # bigger than all "possible" argument lists
16481648
label_namer_pos = 9999 # bigger than all "possible" argument lists
1649-
if (label_namer # we actually want a label here ...
1650-
and arg_names # and we can determine a label in *args ...
1651-
and (label_namer in arg_names)): # and it is in *args
1649+
if (label_namer and # we actually want a label here ...
1650+
arg_names and # and we can determine a label in *args ...
1651+
(label_namer in arg_names)): # and it is in *args
16521652
label_namer_pos = arg_names.index(label_namer)
16531653
if "label" in arg_names:
16541654
label_pos = arg_names.index("label")
@@ -1688,9 +1688,9 @@ def inner(ax, *args, **kwargs):
16881688
# update the information about replace names and
16891689
# label position
16901690
_arg_names = positional_parameter_names(args, data)
1691-
if (label_namer # we actually want a label here ...
1692-
and _arg_names # and we can find a label in *args ...
1693-
and (label_namer in _arg_names)): # and it is in *args
1691+
if (label_namer and # we actually want a label here ...
1692+
_arg_names and # and we can find a label in *args
1693+
(label_namer in _arg_names)): # and it is in *args
16941694
_label_namer_pos = _arg_names.index(label_namer)
16951695
if "label" in _arg_names:
16961696
_label_pos = arg_names.index("label")
@@ -1738,15 +1738,9 @@ def inner(ax, *args, **kwargs):
17381738
)
17391739
if (label_namer and not user_supplied_label):
17401740
if _label_namer_pos < len(args):
1741-
try:
1742-
kwargs['label'] = args[_label_namer_pos].name
1743-
except AttributeError:
1744-
kwargs['label'] = label
1741+
kwargs['label'] = get_label(args[_label_namer_pos], label)
17451742
elif label_namer in kwargs:
1746-
try:
1747-
kwargs['label'] = kwargs[label_namer].name
1748-
except AttributeError:
1749-
kwargs['label'] = label
1743+
kwargs['label'] = get_label(kwargs[label_namer], label)
17501744
else:
17511745
import warnings
17521746
msg = ("Tried to set a label via parameter '%s' in "

lib/matplotlib/axes/_axes.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,47 @@
4040
from matplotlib.axes._base import _AxesBase
4141
from matplotlib.axes._base import _process_plot_format
4242

43+
4344
rcParams = matplotlib.rcParams
4445

4546
iterable = cbook.iterable
4647
is_string_like = cbook.is_string_like
4748
is_sequence_of_strings = cbook.is_sequence_of_strings
4849

4950

51+
def _plot_args_replacer(args, data):
52+
_replacer = []
53+
remaining = args
54+
while 1:
55+
if len(remaining) == 1:
56+
57+
msg = ("Missing argument: this can happen if a color spec "
58+
"('c') is in `data`")
59+
warnings.warn(msg, RuntimeWarning, stacklevel=3)
60+
_replacer += ["x"]
61+
elif len(remaining) == 2:
62+
_replacer += ["x", "y"]
63+
elif len(remaining) == 3:
64+
if remaining[2] in data:
65+
import warnings
66+
67+
msg = "Found a color spec ('c') in data."
68+
warnings.warn(msg, RuntimeWarning, stacklevel=3)
69+
_replacer += ["x", "y", "c"]
70+
71+
if len(remaining) <= 3:
72+
return _replacer
73+
74+
# More than 3 -> split off the beginning and continue
75+
if remaining[2] not in data:
76+
_replacer += ["x", "y", "c"]
77+
isplit = 3
78+
else:
79+
_replacer += ["x", "y"]
80+
isplit = 2
81+
remaining = remaining[isplit:]
82+
83+
5084
# The axes module contains all the wrappers to plotting functions.
5185
# All the other methods should go in the _AxesBase class.
5286

@@ -1245,40 +1279,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
12451279

12461280
return colls
12471281

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 " \
1256-
"('c') is in data"
1257-
warnings.warn(msg, RuntimeWarning, stacklevel=3)
1258-
_replacer += ["x"]
1259-
elif len(remaining) == 2:
1260-
_replacer += ["x", "y"]
1261-
elif len(remaining) == 3:
1262-
if remaining[2] in data:
1263-
import warnings
1264-
1265-
msg = "Found a color spec ('c') in data."
1266-
warnings.warn(msg, RuntimeWarning, stacklevel=3)
1267-
_replacer += ["x", "y", "c"]
1268-
1269-
if len(remaining) <= 3:
1270-
return _replacer
1271-
1272-
# More than 3 -> split off the beginning and continue
1273-
if remaining[2] not in data:
1274-
_replacer += ["x", "y", "c"]
1275-
isplit = 3
1276-
else:
1277-
_replacer += ["x", "y"]
1278-
isplit = 2
1279-
remaining = remaining[isplit:]
1280-
1281-
#### Basic plotting
1282+
# ### Basic plotting
12821283
# The label_naming happens in `matplotlib.axes._base._plot_args`
12831284
@unpack_labeled_data(replace_names=["x", "y"],
12841285
positional_parameter_names=_plot_args_replacer,

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def _plot_args(self, tup, kwargs):
350350
kw[k] = v
351351

352352
if 'label' not in kwargs or kwargs['label'] is None:
353-
kwargs['label'] = get_label(tup[-1])
353+
kwargs['label'] = get_label(tup[-1], None)
354354

355355
if len(tup) == 2:
356356
x = np.atleast_1d(tup[0])

lib/matplotlib/cbook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,11 +2516,11 @@ def get_index_y(y):
25162516
return np.arange(y.shape[0], dtype=float), y
25172517

25182518

2519-
def get_label(y):
2519+
def get_label(y, default_name):
25202520
try:
25212521
return y.name
25222522
except AttributeError:
2523-
return None
2523+
return default_name
25242524

25252525
# Numpy > 1.6.x deprecates putmask in favor of the new copyto.
25262526
# So long as we support versions 1.6.x and less, we need the

0 commit comments

Comments
 (0)