You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Constrained Layout scaling of layouts with submerged spines #23290
I think "constrained_layout=True" breaks the mosaic scaling. For example subplot D is smaller than subplot E in the "Actual Outcome". When I use plot.tight_layout() and contrained_layout=False the subplots are the same size as in the "Expected Outcome"
Code for reproduction
importmatplotlib.pyplotaspltimportmatplotlibasmpldefidentify_axes(ax_dict, fontsize=48):
""" Helper to identify the Axes in the examples below. Draws the label in a large font in the center of the Axes. Parameters ---------- ax_dict : dict[str, Axes] Mapping between the title / label and the Axes. fontsize : int, optional How big the label should be. """kw=dict(ha="center", va="center", fontsize=fontsize, color="darkgrey")
fork, axinax_dict.items():
ax.text(0.5, 0.5, k, transform=ax.transAxes, **kw)
mosaic="""AAADDD AAADDD BBBDDD BBBEEE CCCEEE CCCEEE"""fig=plt.figure(constrained_layout=True)
ax_dict=fig.subplot_mosaic(mosaic)
identify_axes(ax_dict)
Thanks for the report. The dance that has to happen when axes have staggered limits like this is a bit delicate, and clearly doesn't work in this case. Its probably fixable.
What does work is to keep the two in a separate subfigures:
... there is a workaround, so I'll milestone 3.6, though it could easily go in a 3.6 point release as well. I probably can fix this, but it may take some tinkering.
I'm tempted to leave this as wont-fix. In this case, the left hand column has no internal spines in common w/ the righthand column, so it is not particularly useful for them to be in the same layout, and constrained_layout was designed to make lined-up layouts taking into account different decorations on each axes. tight_layout just makes all the spaces around the axes the same, and set by the largest decoration
I'm not arguing that what the OP was doing was at all wrong, but just one of those cases for which constrained_layout is ill-suited.
Again, if you use subfigures or nested mosaics you can get what you want, or you can fallback on tight_layout.
We can keep this open because we should document this case as a time when constrained_layout fails for the constrainedlayout_guide.py
I'm not sure. It's probably possible to post process the positions returned and decide if there are problems. The array of possible problems is pretty undefined, however.
Just to be clear; constrained layout did what we told it to here - it's just that when you span a subplot across subplotspec slots it gets the margins it subsumes as well. Because there are an odd number is subplots in the left column the right column lines up differently for the two subplots.
I think the general warning is that spanning subplotspecs works for many cases, but is fragile in general.
The detection does not have to be exhausting. We don't want false-positive alerts. But it's ok not to wan in every problematic situation. It's already helpful to detect some common specific cases and warn on them.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
[-][Bug]: [/-][+][Bug]: Mosaic Scaling[/+]tacaswell commentedon Jun 16, 2022
attn @jklymak
jklymak commentedon Jun 17, 2022
Thanks for the report. The dance that has to happen when axes have staggered limits like this is a bit delicate, and clearly doesn't work in this case. Its probably fixable.
What does work is to keep the two in a separate subfigures:
jklymak commentedon Jun 17, 2022
... there is a workaround, so I'll milestone 3.6, though it could easily go in a 3.6 point release as well. I probably can fix this, but it may take some tinkering.
jklymak commentedon Jun 18, 2022
I'm tempted to leave this as wont-fix. In this case, the left hand column has no internal spines in common w/ the righthand column, so it is not particularly useful for them to be in the same layout, and constrained_layout was designed to make lined-up layouts taking into account different decorations on each axes. tight_layout just makes all the spaces around the axes the same, and set by the largest decoration
I'm not arguing that what the OP was doing was at all wrong, but just one of those cases for which constrained_layout is ill-suited.
Again, if you use subfigures or nested mosaics you can get what you want, or you can fallback on tight_layout.
We can keep this open because we should document this case as a time when constrained_layout fails for the
constrainedlayout_guide.pytimhoffm commentedon Jun 18, 2022
@jklymak is there a way to detect such cases so that we can issue a waning, possibly with a hint what to do instead.
jklymak commentedon Jun 18, 2022
I'm not sure. It's probably possible to post process the positions returned and decide if there are problems. The array of possible problems is pretty undefined, however.
Just to be clear; constrained layout did what we told it to here - it's just that when you span a subplot across subplotspec slots it gets the margins it subsumes as well. Because there are an odd number is subplots in the left column the right column lines up differently for the two subplots.
I think the general warning is that spanning subplotspecs works for many cases, but is fragile in general.
timhoffm commentedon Jun 18, 2022
The detection does not have to be exhausting. We don't want false-positive alerts. But it's ok not to wan in every problematic situation. It's already helpful to detect some common specific cases and warn on them.
jklymak commentedon Jul 27, 2022
I changed the status here, I suspect this can be fixed, and I'll try to get to it over the next few weeks...
[-][Bug]: Mosaic Scaling[/-][+][Bug]: Constrained Layout scaling of layouts with submerged spines[/+]github-actions commentedon May 4, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
rcomer commentedon May 4, 2026
This would be fixed by #30108, but I'm not clear how.