Skip to content

Colorbar compatible gridspec2 #8758

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

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jun 13, 2017

PR Summary

Git-incompetence (again) makes this a dupe of #8755. @tacaswell already commented, and I made the suggested changes....

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

@jklymak
Copy link
Member Author

jklymak commented Jun 13, 2017

@tacaswell you asked for me to add a "whats new" entry and and "example". More than happy to do so, but not quite clear on how. For the example, something under examples/axes_grid1 ? But I have no idea where the "whats new" should go.

I also note the above is not squashed properly. Working on it ;-)

Thanks, Jody

@tacaswell
Copy link
Member

whats new entry goes in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new (see readme file) and is a quick blurb advertising the new feature.

I think that is a good place for the example. If you are up for it, a longer tutorial showing the (many) ways to set up color bar axes would be great too!

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

jklymak commented Jun 13, 2017

@tacaswell

OK, I actually think that this should be closed and dropped.

I tricked myself into thinking that this worked with tight_layout(), but writing the test cases proved that was not the case.

The fundamental problem, I think, is that tight_layout() really only gives new subplot spacing parameters appropriate for one gridspec, whereas this creates three distinct gridspecs that don't really know about each other. So tight_layout can't suggest useful padding in the vertical or horizontal.

The previous change, #8739, is still useful, and I suggest is superior because it throws a warning when tight_layout() is called.

I guess this hearkens back to #1109. There needs to be ways to group artists together, and then let them expand or contract recursively to fill the space assigned to them. I have trouble even wrapping my head around how that would look.

@tacaswell
Copy link
Member

You are describing a layout manager which can be done with a linear constraint solver (ex https://github.com/nucleic/kiwi). This is basically what tight_layout does, but more general.

@jklymak
Copy link
Member Author

jklymak commented Jun 14, 2017

OK, closing this for now. I have another idea to do something similar using gridspec...

@jklymak jklymak closed this Jun 14, 2017
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.

2 participants