-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Shareable property cyclers #19484
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
Shareable property cyclers #19484
Conversation
While this is a clever way to hack the sharing behavior into the existing structure. However I'm not convinced of this because
IMHO you should share something that is an iterator. So either cyclers would need to become iterators, or you should accept iterators in |
Turning cyclers into iterators is basically going to break anyone c
8000
alling On the other hand, I believe that actually overloading |
Added a test, so this should be good to go -- modulo the discussion of whether we actually want that or not (and under what API), of course... Also split out the first commit (which should be uncontroversial) to #20201. |
16e72cf
to
988df3c
Compare
Allow a single property cycler to be reused across multiple axes, with plots on any axes advancing the same joint iterator. e.g. ```python from matplotlib import pyplot as plt from matplotlib.axes._base import to_shareable_cycler shared = to_shareable_cycler(plt.rcParams["axes.prop_cycle"]) fig, axs = plt.subplots(2, sharex=True) axs[0].set_prop_cycle(shared) axs[1].set_prop_cycle(shared) axs[0].plot([0, 1]) axs[1].plot([0, 1]) # Check that fill uses a separate iterator. axs[1].fill([2, 3, 4], [0, 1, 0]) axs[0].fill([2, 3, 4], [0, 1, 0]) # Check that the second axes goes back to the first color, even though it # didn't use it on the first cycle. for i in range(10): axs[1].plot([5+i, 5+i], [0, 1]) plt.show() ```
Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it. |
First commit: Simplify _process_plot_var_args.set_prop_cycle.
It is private, so we can restrict it to only support cycler instances
and None.
Second commit: Shareable property cyclers.
Allow a single property cycler to be reused across multiple axes, with
plots on any axes advancing the same joint iterator.
e.g.
We may want to move
to_shareable_cycler
and_get_cycling_iterator
to the cycler repo itself (possibly under different names), here I just made them free functions to keep the PR self-contained.An example use case:
(Obviously this is also doable by manually passing the correct colors to each plot call, although it's quite harder to do so if you want to support arbitrary property cycles...)
Closes #19479.