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

Skip to content

Commit 3a2abb5

Browse files
committed
Clarify the implementation of _process_plot_var_args.
Having an argument named `kwargs` that's not a dict but a tuple is just a good way to trip the reader. Fortunately _getdefaults and _setdefaults in only even called with a single kwargs, so we can replace it with a single non-varargs argument and simplify the code at the same time.
1 parent d72f069 commit 3a2abb5

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -235,27 +235,15 @@ def _xy_from_xy(self, x, y):
235235
y = y[:, np.newaxis]
236236
return x, y
237237

238-
def _getdefaults(self, ignore, *kwargs):
238+
def _getdefaults(self, ignore, kw):
239239
"""
240-
Only advance the cycler if the cycler has information that
241-
is not specified in any of the supplied tuple of dicts.
242-
Ignore any keys specified in the `ignore` set.
243-
244-
Returns a copy of defaults dictionary if there are any
245-
keys that are not found in any of the supplied dictionaries.
246-
If the supplied dictionaries have non-None values for
247-
everything the property cycler has, then just return
248-
an empty dictionary. Ignored keys are excluded from the
249-
returned dictionary.
250-
240+
If some keys in the property cycle (excluding those in the set
241+
*ignore*) are absent or set to None in the dict *kw*, return a copy
242+
of the next entry in the property cycle, excluding keys in *ignore*.
243+
Otherwise, don't advance the property cycle, and return an empty dict.
251244
"""
252-
prop_keys = self._prop_keys
253-
if ignore is None:
254-
ignore = set()
255-
prop_keys = prop_keys - ignore
256-
257-
if any(all(kw.get(k, None) is None for kw in kwargs)
258-
for k in prop_keys):
245+
prop_keys = self._prop_keys - ignore
246+
if any(kw.get(k, None) is None for k in prop_keys):
259247
# Need to copy this dictionary or else the next time around
260248
# in the cycle, the dictionary could be missing entries.
261249
default_dict = next(self.prop_cycler).copy()
@@ -265,21 +253,18 @@ def _getdefaults(self, ignore, *kwargs):
265253
default_dict = {}
266254
return default_dict
267255

268-
def _setdefaults(self, defaults, *kwargs):
256+
def _setdefaults(self, defaults, kw):
269257
"""
270-
Given a defaults dictionary, and any other dictionaries,
271-
update those other dictionaries with information in defaults if
272-
none of the other dictionaries contains that information.
273-
258+
Add to the dict *kw* the entries in the dict *default* that are absent
259+
or set to None in *kw*.
274260
"""
275261
for k in defaults:
276-
if all(kw.get(k, None) is None for kw in kwargs):
277-
for kw in kwargs:
278-
kw[k] = defaults[k]
262+
if kw.get(k, None) is None:
263+
kw[k] = defaults[k]
279264

280265
def _makeline(self, x, y, kw, kwargs):
281266
kw = {**kw, **kwargs} # Don't modify the original kw.
282-
default_dict = self._getdefaults(None, kw)
267+
default_dict = self._getdefaults(set(), kw)
283268
self._setdefaults(default_dict, kw)
284269
seg = mlines.Line2D(x, y, **kw)
285270
return seg
@@ -391,8 +376,6 @@ def _grab_next_args(self, *args, **kwargs):
391376

392377

393378
class _AxesBase(martist.Artist):
394-
"""
395-
"""
396379
name = "rectilinear"
397380

398381
_shared_x_axes = cbook.Grouper()

0 commit comments

Comments
 (0)