Skip to content

Add test to colorbar.py to see if ax is an object as returned by plt.subplots #8733

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

Closed
wants to merge 26 commits into from
Closed

Add test to colorbar.py to see if ax is an object as returned by plt.subplots #8733

wants to merge 26 commits into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 8, 2017

…n and turn into a list. This makes colorbar compaticble with the output of plt.subplots (for instance)

PR Summary

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

@@ -1118,6 +1118,8 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
pad = kw.pop('pad', loc_settings['pad'])

# turn parents into a list if it is not already
if isinstance(parents, np.ndarray):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would replace this and the lines below by

parents = np.atleast_1d(parents).ravel().tolist()

(there will never be enough axes for this to be a performance issue...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that seems to work. Very clever!

@jklymak
Copy link
Member Author

jklymak commented Jun 9, 2017

Sorry, my git skills screwed this up. I'll fix with a new pull request once I have it sorted out. My apologies.

@anntzer
Copy link
Contributor

anntzer commented Jun 10, 2017

In desperate cases, you should be able to do something like

# save our work somewhere
$ cp $thefilesyoumodified $temporarydirectory

# pretend it didn't exist -- start from master again
$ git reset --hard master

# put our work back in
$ cp $temporarydirectory $mplrepository

# I swear nothing existed before, this is a new PR
$ git add .
$ git commit
$ git push --force-with-lease

(yes I know there are better ways to do this).

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.

8 participants