Skip to content

[Bug]: layout=compressed conflict with suptitle #30472

@Firestar-Reimu

Description

@Firestar-Reimu

Bug summary

I used layout=compressed to align colorbar and figure, but after I added fig.suptitle the colorbar is not aligned

Actual outcome

If I do not add "fig.suptitle", the colorbar is aligned with the subfigure

Image
import matplotlib.pyplot as plt
import numpy as np

arr = np.arange(100).reshape((10, 10))
fig, ax = plt.subplots(ncols=2, figsize=(4, 2), layout='compressed')
im0 = ax[0].imshow(arr)
im1 = ax[1].imshow(arr)

plt.colorbar(im0, ax=ax[0])
plt.colorbar(im1, ax=ax[1])
plt.show()

If I add "fig.suptitle", the colorbar is slightly longer than the subfigure

Image
import matplotlib.pyplot as plt
import numpy as np

arr = np.arange(100).reshape((10, 10))
fig, ax = plt.subplots(ncols=2, figsize=(4, 2), layout='compressed')
im0 = ax[0].imshow(arr)
im1 = ax[1].imshow(arr)

plt.colorbar(im0, ax=ax[0])
plt.colorbar(im1, ax=ax[1])
fig.suptitle('Title')
plt.show()

Expected outcome

If I do not add "fig.suptitle", the colorbar should still aligned to the subfigure, while added a title above them

Matplotlib Version

3.10.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions