[Bug]: LayoutEngine rect not respected when saving figure with `rcParams['figure.constrained_layout.use'] = True` · Issue #24389 · matplotlib/matplotlib · GitHub
I use the rect parameter of the figure's layout engine to set figure margins. For figures with layout='constrained' this parameter appears to be ignored if rcParams['figure.constrained_layout.use'] is True when saving the figure.
The saved figure does not have the expected layout. It does not match the figure displayed interactively. The axes extend to the edges of the figure area.
Expected outcome
The saved figure has matches what is shown interactively. The axes do not extend to the edges of the figure area, respecting the rect parameter. This saved figure is generated with the code, which does not demonstrate the bug:
What are you trying to accomplish by setting the rcParam? I'm surprised this has any effect on existing figures. If you want to turn constrained layout on or off I'd just do so manually.
I set it in the rcParams because I wanted to use constrained layout by default for all figures in a script. Perhaps my example isn't completely minimal. If the rcParam is set at all, even if the saved figure appears differently from the interactive one.
This was incorrect changing of the layout engine during the print stage, and was fixed in #24167 which was released with 3.6.2. Sorry this broke. Essentially a duplicate of #24133.
BTW, you should not need the engine.execute(fig) step as that gets called upon either show or savefig
Activity
jklymak commented on Nov 7, 2022
What are you trying to accomplish by setting the rcParam? I'm surprised this has any effect on existing figures. If you want to turn constrained layout on or off I'd just do so manually.
s-bear commented on Nov 7, 2022
s-bear commented on Nov 7, 2022
I just edited the bug report to make the example code more consise and demonstrate the issue more clearly. Cheers, Sam
jklymak commented on Nov 7, 2022
This was incorrect changing of the layout engine during the print stage, and was fixed in #24167 which was released with 3.6.2. Sorry this broke. Essentially a duplicate of #24133.
BTW, you should not need the engine.execute(fig) step as that gets called upon either show or savefig
tacaswell commented on Nov 7, 2022
I can confirm that this is fixed in 3.6.2.
Thank you for the very clear example @s-bear !