Description
Summary
Currently the prop_cycle code (in _process_plot_var_args) creates an itertools.cycle over the Cycler instance to yield the successive line properties. itertools.cycle objects are opaque, which creates some difficulties e.g. in _parse_scatter_color_args which needs to use self._get_patches_for_fill.get_next_color to workaround the impossibility to peek at the next color in the cycle without advancing the iterator, and also with pickling (currently we just completely drop the cycler state when pickling/unpickling).
An alternative would be to drop the use of itertools.cycle and instead simply store in _process_plot_var_args both the Cycler object and an integer index, which simply gets incremented at each use, and add support for indexing Cyclers (perhaps something like cycler.get_nth(idx)
or forcing the caller to explicitly write cycler[idx % len(cycler)]
, to avoid confusion with the fact that len(cycler)
returns the finite, non-cycled length).
This would both make peeking at the next color easier, and directly solve the issue of picklability.
Proposed fix
No response