Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
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 thebbox_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 tofig.savefig
.
Code for reproduction
importmatplotlib.pyplotaspltfig,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 unchangedextent2=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 ofaxs[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.