-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Made colorbar.py accept numpy array input, compatible with output fro… #8739
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
Made colorbar.py accept numpy array input, compatible with output fro… #8739
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR reverts a bunch of recent changes. Please base it off master.
56028ea
to
0e339a1
Compare
0e339a1
to
4ace2a4
Compare
Phew, OK, think I figured out all the rebasing. @anntzer thanks for the hand-holding. |
lib/matplotlib/colorbar.py
Outdated
# turn parents into a list if it is not already. We do this w/ np | ||
# because `ax=plt.subplots(1,1)` is an ndarray and is natural to | ||
# pass to `colorbar`. | ||
parents = np.atleast_1d(parents).ravel().tolist() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it looks like you can drop the tolist()
, a flat array should be just fine.
lib/matplotlib/colorbar.py
Outdated
if not isinstance(parents, (list, tuple)): | ||
parents = [parents] | ||
# turn parents into a list if it is not already. We do this w/ np | ||
# because `ax=plt.subplots(1,1)` is an ndarray and is natural to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picky thing, but this comment is not quite right, should should be fig, ax_arr = plt.subplots(squeeze=False)
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"We do this because plt.subplots can return axes in an ndarray and ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Picky is good. Thanks, now reads:
# turn parents into a list if it is not already. We do this w/ np
# because `plt.subplots` can return an ndarray and is natural to
# pass to `colorbar`.
parents = np.atleast_1d(parents).ravel()
👍 modulo comment about comment. |
Test failures are due to warning -> error from numpy 1.13 |
Accept a wider range of iterables for `ax`.
PR Summary
This is a duplicate of #8733. Appologies to @anntzer who reviewed the previous, and suggested the fix used here.
fig.colorbar(pcm=pcm,ax=axs)
can take a list of axes objects as the argument to ax. However,axs=plt.subplots(2,1)
returns a numpyobject
. This PR simply checks ifaxs
is an object and flattens and makes the object a list. Now commands like:will take space away from all the subplots, and put a colorbar on the right of all four subplots.
PR Checklist