8000 Fix pickling of axes property cycle. by anntzer · Pull Request #26341 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix pickling of axes property cycle. #26341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
Merged

Fix pickling of axes property cycle. #26341

merged 1 commit into from
Jul 20, 2023

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Jul 18, 2023

Instead of relying on itertools.cycle (which is unpicklable, and leads to the axes property cycle being reset to the rcparams value upon unpickling), use a plain, trivially picklable, list-and-index representation (the property cycle is guaranteed to be finite because Axes.set_prop_cycle passes its argument through matplotlib.cycler, which already iterates through all cycler values for validation purposes).

Unfortunately this is not enough to really get rid of the get_next_color/get_next_color_func awkwardness, which also serves the additional purpose of not unnecessarily advancing the prop_cycle when it does not contain a "color" key and a color is requested.

Closes #26082.

PR summary

PR checklist

@anntzer anntzer force-pushed the pc branch 2 times, most recently from 18d4a4b to ea73803 Compare July 18, 2023 14:40
@QuLogic
Copy link
Member
QuLogic commented Jul 18, 2023

This broke some Sankey examples (which probably should be tested better, I guess.)

Instead of relying on itertools.cycle (which is unpicklable, and leads
to the axes property cycle being reset to the rcparams value upon
unpickling), use a plain, trivially picklable, list-and-index
representation (the property cycle is guaranteed to be finite because
Axes.set_prop_cycle passes its argument through matplotlib.cycler, which
already iterates through all cycler values for validation purposes).

Unfortunately this is not enough to really get rid of the
get_next_color/get_next_color_func awkwardness, which also serves the
additional purpose of not unnecessarily advancing the prop_cycle when it
does not contain a "color" key and a color is requested.
@anntzer
Copy link
Contributor Author
anntzer commented Jul 19, 2023

Woops, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MNT]: Make cyclers indexable and rely on indexing them rather than itertools.cycle
3 participants
0