Skip to content

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

Merged
merged 3 commits into from
Jun 12, 2017

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 9, 2017

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 numpy object. This PR simply checks if axs is an object and flattens and makes the object a list. Now commands like:

fig,axs = plt.subplots(2,2)
pcm = axs[0,0].pcolormesh(np.random.rand(30,30),vmin=-1.,vmax=1.)
fig.colorbar(pcm=pcm,ax=axs)

will take space away from all the subplots, and put a colorbar on the right of all four subplots.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/whats_new.rst if major new feature
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Contributor

@anntzer anntzer left a 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.

@jklymak jklymak force-pushed the colorbar-compatible-subplots2 branch from 56028ea to 0e339a1 Compare June 10, 2017 22:36
@jklymak jklymak force-pushed the colorbar-compatible-subplots2 branch from 0e339a1 to 4ace2a4 Compare June 10, 2017 22:54
@jklymak
Copy link
Member Author

jklymak commented Jun 10, 2017

Phew, OK, think I figured out all the rebasing. @anntzer thanks for the hand-holding.

# 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()
Copy link
Contributor

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.

@anntzer anntzer dismissed their stale review June 10, 2017 23:52

comment handled

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
Copy link
Member

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.

Copy link
Contributor

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 ..."

Copy link
Member Author

@jklymak jklymak Jun 11, 2017

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()

@tacaswell
Copy link
Member

👍 modulo comment about comment.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jun 11, 2017
@tacaswell
Copy link
Member

Test failures are due to warning -> error from numpy 1.13

@tacaswell tacaswell merged commit 3a58953 into matplotlib:master Jun 12, 2017
@jklymak jklymak deleted the colorbar-compatible-subplots2 branch June 12, 2017 02:23
jklymak added a commit to jklymak/matplotlib that referenced this pull request Jun 13, 2017
Accept a wider range of iterables for `ax`.
@jklymak jklymak mentioned this pull request Jun 13, 2017
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants