Closed
Description
Bug report
Bug summary
This relies on #20723 being addressed.
As reported in a comment on that issue, a legend added to a SubFigure
is not included when calculating the bbox of the parent figure and so the subfigure legend is cut off the plot when saving a figure with bbox_inches="tight"
.
Code for reproduction
import matplotlib.pyplot as plt
fig = plt.figure()
subfig = fig.subfigures()
ax = subfig.subplots()
ax.plot([0, 1, 2], [0, 1, 2], label="test")
subfig.legend()
print(fig.get_default_bbox_extra_artists())
plt.savefig("test.png", bbox_inches="tight")
Actual outcome
[<matplotlib.figure.SubFigure at 0x7fc17864e700>,
<matplotlib.lines.Line2D at 0x7fc17874aa90>,
<matplotlib.spines.Spine at 0x7fc178612700>,
<matplotlib.spines.Spine at 0x7fc178612910>,
<matplotlib.spines.Spine at 0x7fc178612c70>,
<matplotlib.spines.Spine at 0x7fc17864e5e0>,
<matplotlib.axis.XAxis at 0x7fc178612c10>,
<matplotlib.axis.YAxis at 0x7fc17864ed60>,
<matplotlib.patches.Rectangle at 0x7fc178738730>]
Expected outcome
The subfigure legend should be included in the bbox.
Matplotlib version
- Operating system: Mac OS 11.4
- Matplotlib version (
import matplotlib; print(matplotlib.__version__)
): 3.4.2 - Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.8.3
Metadata
Metadata
Assignees
Labels
No labels