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

Skip to content

Commit d60a9cc

Browse files
committed
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).
1 parent 3efd447 commit d60a9cc

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,21 @@ class _process_plot_var_args:
223223
def __init__(self, axes, command='plot'):
224224
self.axes = axes
225225
self.command = command
226-
self.set_prop_cycle()
226+
self.set_prop_cycle(None)
227227

228228
def __getstate__(self):
229229
# note: it is not possible to pickle a generator (and thus a cycler).
230230
return {'axes': self.axes, 'command': self.command}
231231

232232
def __setstate__(self, state):
233233
self.__dict__ = state.copy()
234-
self.set_prop_cycle()
234+
self.set_prop_cycle(None)
235235

236-
def set_prop_cycle(self, *args, **kwargs):
237-
# Can't do `args == (None,)` as that crashes cycler.
238-
if not (args or kwargs) or (len(args) == 1 and args[0] is None):
239-
prop_cycler = mpl.rcParams['axes.prop_cycle']
240-
else:
241-
prop_cycler = cycler(*args, **kwargs)
242-
243-
self.prop_cycler = itertools.cycle(prop_cycler)
244-
# This should make a copy
245-
self._prop_keys = prop_cycler.keys
236+
def set_prop_cycle(self, cycler):
237+
if cycler is None:
238+
cycler = mpl.rcParams['axes.prop_cycle']
239+
self.prop_cycler = itertools.cycle(cycler)
240+
self._prop_keys = cycler.keys # This should make a copy
246241

247242
def __call__(self, *args, data=None, **kwargs):
248243
self.axes._process_unit_info(kwargs=kwargs)

0 commit comments

Comments
 (0)