-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: compressed layout #22289
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
ENH: compressed layout #22289
Conversation
lib/matplotlib/layout_engine.py
Outdated
@@ -205,6 +205,8 @@ def __init__(self, *, h_pad=None, w_pad=None, | |||
hspace=mpl.rcParams['figure.constrained_layout.hspace']) | |||
# set anything that was passed in (None will be ignored): | |||
self.set(w_pad=w_pad, h_pad=h_pad, wspace=wspace, hspace=hspace) | |||
# see CompressedLayoutEngine below... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems wrong now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops, yes, I decided against needing a subclass here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs fixing?
dcca890
to
8175f87
Compare
e445e28
to
777b8ef
Compare
ead8ac7
to
e303fbb
Compare
lib/matplotlib/layout_engine.py
Outdated
@@ -205,6 +205,8 @@ def __init__(self, *, h_pad=None, w_pad=None, | |||
hspace=mpl.rcParams['figure.constrained_layout.hspace']) | |||
# set anything that was passed in (None will be ignored): | |||
self.set(w_pad=w_pad, h_pad=h_pad, wspace=wspace, hspace=hspace) | |||
# see CompressedLayoutEngine below... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs fixing?
fig, axs = plt.subplots(2, 2, figsize=(5, 3), | ||
sharex=True, sharey=True, layout='compressed') | ||
for ax in axs.flat: | ||
ax.imshow(arr) | ||
fig.suptitle("fixed-aspect plots, layout='compressed'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to look the same as the constrained version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I have no idea what is happening here. This example works fine manually, just using Agg, etc. I'm flummoxed why the sphinx version doesn't work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in newest version - there was some weird interactions between the rcParam and subsequent calls. maybe worth chasing down, but I could not reproduce without sphinx-gallery, so I guess sphinx-galery is using some weird rcParam contexts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the context remains the same through a single file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but even if I change the rcParam in a normal script, and then specify the kwarg, compress
works fine. But in sphinx- gallery it has this weird problem.
5380aa1
to
dbcb46c
Compare
f14b4bb
to
1adfa9d
Compare
1adfa9d
to
421c99e
Compare
fig, axs = plt.subplots(2, 2, figsize=(5, 3), | ||
sharex=True, sharey=True, layout='compressed') | ||
for ax in axs.flat: | ||
ax.imshow(arr) | ||
fig.suptitle("fixed-aspect plots, layout='compressed'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the context remains the same through a single file.
@@ -84,10 +85,13 @@ def do_constrained_layout(fig, h_pad, w_pad, | |||
A value of 0.2 for a three-column layout would have a space | |||
of 0.1 of the figure width between each column. | |||
If h/wspace < h/w_pad, then the pads are used instead. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with above, this empty line should be here (and one added after the rect
description) or all above also removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, though this is private, so never rendered in the docs ;-)
421c99e
to
1984d55
Compare
Adds compress=True to compressed layout engine. Works for compact axes grids.
1984d55
to
44df2db
Compare
I've marked merge with single review. This is pretty stand alone, so it shouldn't break anyone. However, happy to get a second review. I'll merge by next Friday if it doesn't attract one. |
Thanks everyone for your work on this! |
Thanks for creating this! 😄 |
PR Summary
Replaces #20016
We often want a grid of fixed-aspect ratio axes, but constrained_layout and tigt_layout leave large blank spaces between the axes because they only work with the original axes positions, not the aspect-modified versions.
Here I proposed an extension to constrianed_layout that works for simple grids of axes...
Old:
New:
Code
Failures...
This isn't perfect, and that is why it is not in "constrained_layout" Folks should be able to turn this off... This example isn't terrible, but its not very good either, though
Or:
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).