From d60a9ccff3c4c9f53986261c1f583ff9debe7945 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 9 Feb 2021 18:55:55 +0100 Subject: [PATCH] Simplify _process_plot_var_args.set_prop_cycle. It is private, so we can restrict it to only support Cycler instances and None (rather than also supporting `*args, **kwargs` from which a new Cycler is constructed: the caller Axes.set_prop_cycle already takes care of conversion into Cycler instances). --- lib/matplotlib/axes/_base.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 9898c7c7503c..f72e2950100f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -223,7 +223,7 @@ class _process_plot_var_args: def __init__(self, axes, command='plot'): self.axes = axes self.command = command - self.set_prop_cycle() + self.set_prop_cycle(None) def __getstate__(self): # note: it is not possible to pickle a generator (and thus a cycler). @@ -231,18 +231,13 @@ def __getstate__(self): def __setstate__(self, state): self.__dict__ = state.copy() - self.set_prop_cycle() + self.set_prop_cycle(None) - def set_prop_cycle(self, *args, **kwargs): - # Can't do `args == (None,)` as that crashes cycler. - if not (args or kwargs) or (len(args) == 1 and args[0] is None): - prop_cycler = mpl.rcParams['axes.prop_cycle'] - else: - prop_cycler = cycler(*args, **kwargs) - - self.prop_cycler = itertools.cycle(prop_cycler) - # This should make a copy - self._prop_keys = prop_cycler.keys + def set_prop_cycle(self, cycler): + if cycler is None: + cycler = mpl.rcParams['axes.prop_cycle'] + self.prop_cycler = itertools.cycle(cycler) + self._prop_keys = cycler.keys # This should make a copy def __call__(self, *args, data=None, **kwargs): self.axes._process_unit_info(kwargs=kwargs)