Skip to content

Make colorbar compatible accepting a list of axes created via gridspec #8755

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 27 commits into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 13, 2017

PR Summary

Similar to #8739, but modifies make_axes_gridspec in colorbar.py.

This is a change to make figure.colorbar(ppm,ax=parents) accept a list of parents that are SubplotBase, and were created by gridspec and return a colorbar that is SubplotBase. So a call like:

fig, axs = plt.subplots(2,2)
pcm = axs[0,0].pcolormesh(np.random(32,32))
fig.colorbar(ppm, ax=axs)
fig.tight_layout()

works with axs as a list, and colorbar taking space from all the axes listed by axs, and tight_layout() able to operate on all axes including the colorbar.

I think it works for most edge cases. I hesitated to edit the test suite, but could give that a try if desired.

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

@tacaswell
Copy link
Member

Can you squash this to one or two commits?

dstansby and others added 27 commits June 13, 2017 06:33
Removed some debug statements and old comments; whitespace / line
wrapping.

In particular, debug comments which simply indicate that
a function has been called can easily be replaced by
tools such as https://pypi.python.org/pypi/hunter or
https://pypi.python.org/pypi/smiley.
2.5.5 is what's in my conda env, and 2.6.1 is what's built with the
local_freetype option and is used on Travis and AppVeyor without issue.
The result of id() is only guaranteed to be unique for objects that
exist at the same time. This global integer is a quick and light way to
ensure that new renderers that match an old one don't produce the same
caching key.
The Mathtext tests should no longer be flaky based on the previous
change.

Mark some PS tests as flaky because they require a lock that sometimes
gets stuck on AppVeyor due to the multiple processes.
Accept a wider range of iterables for `ax`.
…ng in magnitude_spectrum() and fixed doc string.
when building packages (e.g. for openSUSE Linux)
(random) filesystem order of input files
influences ordering of functions in the output,
thus without the patch, builds (in disposable VMs) would usually differ.

See https://reproducible-builds.org/ for why this matters.
@jklymak jklymak force-pushed the colorbar-compatible-gridspec branch from a7e484c to d9b49b5 Compare June 13, 2017 13:34
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Nice work!

One small API change this should be reverted.

This needs a whats_new entry and an example.

@docstring.Substitution(make_axes_kw_doc)
def make_axes_gridspec(parent, **kw):
def make_axes_gridspec(parents, **kw):
Copy link
Member

Choose a reason for hiding this comment

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

Changing the argument name is an API change (as make_akes_gridspec(parent=obj) will be broken).

# the maximum and minimum index into the subplotspec. The result is the
# size the new gridspec that we will create must be.
gsp0 = parents[0].get_subplotspec().get_gridspec()
minind = 10000
Copy link
Member

Choose a reason for hiding this comment

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

Probably better to use np.inf and -np.inf or use the values from the first parent.

@@ -13,19 +13,19 @@
# set this to True. It will download and build a specific version of
# FreeType, and then use that to build the ft2font extension. This
# ensures that test images are exactly reproducible.
#local_freetype = False
local_freetype = True
Copy link
Member

Choose a reason for hiding this comment

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

These changes should not be committed

@jklymak
Copy link
Member Author

jklymak commented Jun 13, 2017

Hmm, apparently not.. added a bunch of other files somehow. Sigh

@tacaswell
Copy link
Member

You need to force-push to github, at some point when you are trying to push the rebased branch it is saying "Can not push, please merge upstream changes first"?

See #2742 for detailed instructions on how to deal with rebasing (which has annoyingly been removed from our built documentation...)

@jklymak
Copy link
Member Author

jklymak commented Jun 13, 2017

yeah, but I did my rebase wrong. I foolishly thought I didn't have to count the commits... I'm going to start over. Sorry for my bad git skills

@jklymak jklymak closed this Jun 13, 2017
@jklymak jklymak mentioned this pull request Jun 13, 2017
6 tasks
@tacaswell
Copy link
Member

I strongly recommend using gitk or other GUI tool that will show you the actual graph (git log --graph) rather than the flattened version github shows you.

Cherry-picking ranges can also be superhelpful for fixing this sort of thing.

http://tom.preston-werner.com/2009/05/19/the-git-parable.html <- this is what made me actually understand git.

@tacaswell
Copy link
Member

and making git-snarls is an unfortunate, but real part of learning to use git.

@jklymak
Copy link
Member Author

jklymak commented Jun 13, 2017

I'll maintain that I understand git just fine, but git doesn't understand me ;-)

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