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

Skip to content

Enh/extend mosaic kwargs #24604

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 8 commits into from
Dec 29, 2022
Merged

Conversation

tacaswell
Copy link
Member

PR Summary

Closes #24571

Open questions:

  • do we want this?
  • what should the name be?
  • is it exciting enough to get a whats new?

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@tacaswell tacaswell added this to the v3.7.0 milestone Dec 3, 2022
@story645 story645 marked this pull request as ready for review December 3, 2022 23:15
@story645 story645 marked this pull request as draft December 3, 2022 23:17
@rcomer
Copy link
Member

rcomer commented Dec 5, 2022

I would use it, and I’d be excited to read about it in the what’s new. For a name, maybe something like per_subplot_kw or mapped_subplot_kw?

@story645
Copy link
Member

story645 commented Dec 5, 2022

For a name, maybe something like per_subplot_kw or mapped_subplot_kw?

I'm concerned about having two keyword arguments that are circular references to each other. What I mean is the docs are something like:

  • subplot_kw: dictionary of keyword arguments passed through for all subplots, per_subplot_kw takes precedence when there's a conflict
  • per_subplot_kw: dictionary of keyword arguments passed through for individual subplots, defaults to subplot_kw

My concern is that coupled parameters leads to confusion about which parameter to use and what is prioritized; for example, confusion around colors. If consensus is that keeping these parameters separate is a good idea for the default fall through, then I think they should at least follow each other in the documentation and not be separated by the gridspec_kw.

@anntzer
Copy link
Contributor

anntzer commented Dec 5, 2022

per_subplot_kw doesn't default to subplot_kw, though. It would be "additional keyword arguments passed to the subplot constructors; take precedence over conflicting entries in subplot_kw".

@tacaswell
Copy link
Member Author

I like mapped_subplot_kw. It is a bit long, but it makes the point that it is mapped (and "to the keys in the mosaic" is a logical thing to have shared keys with, and it is the keywords passed to add_subplot)

@story645
Copy link
Member

story645 commented Dec 5, 2022

"take precedence over conflicting entries in subplot_kw"

As mentioned in #24571, when there's no conflict any arguments passed to 'subplot_kw' are applied (line 2063-2064), which is why I'm calling that the default/(edit is probably more appropriate to say that subplot_kw is the fallback). But more to my point, the dev calling this function has to keep track of what they passed to both parameters when either one seems to be behaving strangely.

@tacaswell
Copy link
Member Author

Other proposals

  • by_subplot_kw
  • by_label_subplot_kw

and post fixing a modifier (from call with @QuLogic and @ksunden ).

@tacaswell tacaswell force-pushed the enh/extend_mosaic_kwargs branch from 6ca4fbb to c058015 Compare December 8, 2022 22:06
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 8, 2022
@tacaswell tacaswell marked this pull request as ready for review December 8, 2022 22:07
@tacaswell
Copy link
Member Author

per the call:

  • named per_subplot_kw
  • put next to subplot_kw docstring

@tacaswell tacaswell force-pushed the enh/extend_mosaic_kwargs branch from a724652 to 562ba8d Compare December 9, 2022 18:08
@@ -1821,6 +1841,9 @@ def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,
The string notation allows only single character Axes labels and
does not support nesting but is very terse.

Tuples may be used instead of lists and tuples may not be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuples may be used instead of lists

Do we want to allow this explicitly? I'm in favor of having one documented and recommended way, so that usages are consistent and not half of the people are using lists and the other half tuples.
It's a separate topic that tuples are accepted due to duck-typing and can be used in special situations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree to drop the first half of this sentence as many things will "work":

import matplotlib.pyplot as plt
from collections import deque

a = deque([deque(['A', 'B']), deque(['C', 'D'])])
plt.subplot_mosaic(a)
plt.show()

but we should only document one spelling. In the tutorial I think we also pass a 2D numpy array.

Maybe the input should be "something coercible to a numpy object array of hashables"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also "works" 🤦🏻

plt.subplot_mosaic(frozenset([frozenset('ab'), frozenset('cd')]))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this wording.

On one hand, no one has complained that they can not use tuples as keys yet, on the other hand if we take "tuple is broadcast" in this PR then relaxing this in the future would cost of some tricky logic around sorting out what to do about:

plt.subplot_mosaic([[('a', 'b'), 'a'], ['b', 'c']], per_subplot_kw={('a', 'b'): {}})

I think you have to always treat the tuple as "can I broadcast this" first and then we decide if we fallback to "maybe this is a key?" (as if you do it the other way you can never broadcast to 'a' and 'b' in this case). We might also be able to break this ambiguity by requiring tuple keys to always be nested in another tuple for per_subplot_kw as {(('a', 'b'),): {}} which is annoying, but not the worst.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wording as you have written it now is the correct solution:

The Axes identifiers may be str or a non-iterable hashable object (e.g. tuple s may not be used).

Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some tiny doc suggestions. Also should the new keyword be included in the pyplot.subplot_mosaic docstring?

Otherwise, this looks good to me.

@tacaswell
Copy link
Member Author

@rcomer pyplot should be updated, thank you for catching that!

@tacaswell
Copy link
Member Author

Drat, I have been seeing those docs build failures locally for a while now and had not chased them down the source of the problem. Given that numpy 1.24 just came out I am now confident that it was a change to numpy, looking into this....

@tacaswell
Copy link
Member Author

ok, I understand the doc failure and will open a separate PR to fix it.

@tacaswell tacaswell force-pushed the enh/extend_mosaic_kwargs branch from 68d53c3 to 5b0fb4a Compare December 21, 2022 20:26
Co-authored-by: Elliott Sales de Andrade <[email protected]>
@QuLogic QuLogic force-pushed the enh/extend_mosaic_kwargs branch from aa3cda5 to e56f876 Compare December 29, 2022 20:24
@greglucas greglucas merged commit 65e54af into matplotlib:main Dec 29, 2022
@tacaswell tacaswell deleted the enh/extend_mosaic_kwargs branch January 3, 2023 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH]: gridspec_mosaic
7 participants