8000 [Bug]: Top of plot clipped when using Subfigures without suptitle · Issue #21839 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: Top of plot clipped when using Subfigures without suptitle #21839
Closed
@sponde25

Description

@sponde25

Bug summary

When using subfigures without setting a suptitle for the root figure, the top of the plot is clipped out. This includes the suptitle for the top subfigure.

Code for reproduction

def example_plot(ax, fontsize=12, hide_labels=False):
    pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2.5, vmax=2.5)
    if not hide_labels:
        ax.set_xlabel('x-label', fontsize=fontsize)
        ax.set_ylabel('y-label', fontsize=fontsize)
        ax.set_title('Title', fontsize=fontsize)
    return pc

np.random.seed(19680808)
# gridspec inside gridspec
fig = plt.figure(constrained_layout=True, figsize=(10, 4))
subfigs = fig.subfigures(1, 2, wspace=0.07)

axsLeft = subfigs[0].subplots(1, 2, sharey=True)
subfigs[0].set_facecolor('0.75')
for ax in axsLeft:
    pc = example_plot(ax)
subfigs[0].suptitle('Left plots', fontsize='x-large')
subfigs[0].colorbar(pc, shrink=0.6, ax=axsLeft, location='bottom')

axsRight = subfigs[1].subplots(3, 1, sharex=True)
for nn, ax in enumerate(axsRight):
    pc = example_plot(ax, hide_labels=True)
    if nn == 2:
        ax.set_xlabel('xlabel')
    if nn == 1:
        ax.set_ylabel('ylabel')

subfigs[1].set_facecolor('0.85')
subfigs[1].colorbar(pc, shrink=0.6, ax=axsRight)
subfigs[1].suptitle('Right plots', fontsize='x-large')

# fig.suptitle('Figure suptitle', fontsize='xx-large')
plt.show()

Actual outcome

bug_report

Expected outcome

expected_report

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.4.3

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

3.8

Jupyter version

6.0.3

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0