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 summary
I'm not sure whether this is really a bug or I'm just using an inconsistent combination of options. Under some specific circumstances (see below) compressed layout is not applied the second time a figure is saved.
Code for reproduction
importmatplotlibimportmatplotlib.pyplotaspltimportnumpyasnparr=np.arange(100).reshape((10,10))matplotlib.rcParams['figure.constrained_layout.use']=Truefig,ax_dict=plt.subplot_mosaic('AB;AC',figsize=(6,9),width_ratios=[3,2],layout='compressed')forkeyin ["B","C"]:ax_dict[key].imshow(arr)fig.savefig("test1.png",bbox_inches="tight")fig.savefig("test2.png",bbox_inches="tight")
Actual outcome
Expected outcome
Both images should look like the first.
Additional information
If I do not set thercParams
, all is well. If I do not setbbox_inches="tight"
in my calls tosavefig
, the images are identical (but I have too much white space top and bottom). Maybe there is a better option thanbbox_inches="tight"
when using compressed layout?
For context, my real example is a script that makes several figures. For most of them I want constrained layout, so I set that once in thercParams
for convenience. Only one figure needs "compressed", and I am saving twice because I want both a png and a pdf. Fixed it in my current example by just reverting thercParams
setting for the one figure.
Operating system
RHEL7
Matplotlib Version
3.6.2 and main
Matplotlib Backend
QtAgg
Python version
3.9 and 3.11
Jupyter version
No response
Installation
conda