Closed
Description
Bug report
Bug summary
When calculating the extent of a subplot axes, its contents depend on whether title has been set in the axes below, i. e. the unrelated title bleeds into the extent and gets exported when saving while specifying the bbox_inches
.
The extent itself doesn't seem to be the problem, but the inclusion of artefacts that should not be included in the plot, and aren't visible in the full figure (in the bounding box) are included and saved when giving an explicit bounding box to fig.savefig
.
Code for reproduction
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1)
axs[0].plot([1,2], [3,4])
extent = axs[0].get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig('/tmp/expected.png', bbox_inches=extent)
axs[1].set_title('pls ignore me')
# extents are actually unchanged
extent2 = axs[0].get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig('/tmp/actual.png', bbox_inches=extent2)
fig.savefig('/tmp/full.png')
Actual outcome
The title of axs[1]
is shown.
Expected outcome
It should not be included, as visible in the full picture.
Matplotlib version
- Operating system:
- Matplotlib version: 3.2.1
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.8.2
Environment has been installed with the default conda channel.
Metadata
Metadata
Assignees
Labels
LayoutEngine, Constrained layout, Tight layoutLayoutEngine, Constrained layout, Tight layout