Skip to content

ENH: Compressed layout for fixed-aspect axes #17246

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

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Apr 26, 2020

PR Summary

EDIT 5 May: new write up here...

Adds a new layout option compress_layout=True to Figure.figure. This option attempts to compress axes if they are too far apart because of fixed aspect ratios....

This is most feature complete with constrained_layout=True, but works if folks don't use colorbars for no layout or tight_layout. The real issue is that we cannot handle nested gridspecs with this, and colorbars, by default, are nested gridspecs. (Don't get me started on how we make colorbars - I think that needs a rethink).

See new example: https://36260-1385122-gh.circle-artifacts.com/0/doc/build/html/gallery/subplots_axes_and_figures/compress_axes.html#sphx-glr-gallery-subplots-axes-and-figures-compress-axes-py

Before:

fig, axs = plt.subplots(2, 2, figsize=(5, 3), facecolor='0.75',
                        sharex=True, sharey=True, constrained_layout=True)
for ax in axs.flat:
    ax.set_aspect(1.0)
plt.show()

OldCL

After

fig, axs = plt.subplots(2, 2, figsize=(5, 3), facecolor='0.75',
                        sharex=True, sharey=True, constrained_layout=True, 
                        compress_layout=True)
for ax in axs.flat:
    ax.set_aspect(1.0)
plt.show()

NewCL

PR Checklist

  • suptitle!

  • Has Pytest style unit tests

  • Code is Flake 8 compliant

  • New features are documented, with examples if plot related

  • Documentation is sphinx and numpydoc compliant

  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)

  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak marked this pull request as draft April 26, 2020 19:43
@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Apr 26, 2020
@jklymak jklymak added this to the v3.3.0 milestone Apr 26, 2020
@jklymak jklymak mentioned this pull request Apr 26, 2020
6 tasks
@jklymak jklymak added the status: needs comment/discussion needs consensus on next step label Apr 29, 2020
@jklymak jklymak modified the milestones: v3.3.0, v3.4.0 Apr 29, 2020
@jklymak
Copy link
Member Author

jklymak commented Apr 29, 2020

Remilestoned for 3.4, but would be nice to get some comment for this. Is a string value for the constrained_layout kwarg OK? "squish" OK or does someone have a better name?

I think it would be possible for the just to be run all the time when CL is turned on; its quite fast, but I've not tried every weird combo of axes yet.

I also think it would be possible to run this stand-alone. _squish doesn't actually rely on anything in CL. Its nice though to have it injected at the draw stage because otherwise the user has to trigger a draw manually.

@anntzer
Copy link
Contributor

anntzer commented Apr 29, 2020

Are the axes not squished horizontally because of the long xlabels? If so it may be nice to provide an example where squishing occurs in both directions.

@jklymak
Copy link
Member Author

jklymak commented Apr 29, 2020

@anntzer Not quite sure what you mean. The aspect ratio of the figure is such that squishing only happens in x in this case, but if the aspect ratios were swapped the squishing happens in x.

If you mean the spacing is different between the axes in x and y, then yes, thats because of the large x-labels. The point of constrained_layout is non-overlapping labels, so thats a feature, not a bug.

If instead we want a layout where labels are allowed to overlap and the plot positions are simply a fixed distance apart, then that is really a lot easier than what is done here since you can do all the positioning with the axes positions and don't need to know about the size of the decorations.

@jklymak jklymak force-pushed the CL-squish-fixed-aspect branch from 8bf58b8 to a95ac4a Compare May 3, 2020 23:11
@jklymak jklymak force-pushed the CL-squish-fixed-aspect branch from 718edaa to 523ffee Compare May 5, 2020 22:33
@jklymak jklymak changed the title Cl squish fixed aspect ENH: Compressed layout for fixed-aspect axes May 6, 2020
**self._tight_parameters)
# convert pads to inches...
fs = FontProperties(size=mpl.rcParams["font.size"])
fs = fs.get_size_in_points() / 72
Copy link
Member Author

Choose a reason for hiding this comment

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

This flake8 error looks spurious?

@jklymak jklymak marked this pull request as ready for review May 6, 2020 16:12
@jklymak jklymak marked this pull request as draft May 27, 2020 15:22
@jklymak jklymak removed the status: needs comment/discussion needs consensus on next step label Aug 14, 2020
@jklymak
Copy link
Member Author

jklymak commented Dec 19, 2020

I'm closing this, not because I think its a bad idea, but because it needs to be substantially revised with the new CL changes.

@jklymak jklymak closed this Dec 19, 2020
@jklymak jklymak deleted the CL-squish-fixed-aspect branch December 19, 2020 21:47
@QuLogic QuLogic removed this from the v3.4.0 milestone Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants