[Bug]: Changing GridSpec column/row ratios after axes creation does not update the figure layout · Issue #31971 · matplotlib/matplotlib · GitHub
Skip to content

[Bug]: Changing GridSpec column/row ratios after axes creation does not update the figure layout #31971

Description

@jayaprajapatii

Bug summary

Updating a GridSpec's width or height ratios after axes have already been added to it has no visible effect — the figure layout silently stays unchanged, even though the internal state is updated correctly.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

fig = plt.figure()
gs = gridspec.GridSpec(1, 3, figure=fig, width_ratios=[1, 2, 1])
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[0, 2])
fig.canvas.draw()

print("Before:", round(ax2.get_position().width, 4))

gs.set_width_ratios([1, 1, 1])
fig.canvas.draw()

print("After: ", round(ax2.get_position().width, 4))

fig.savefig('test.png')
plt.show()

Actual outcome

Before: 0.3419
After: 0.3419

Image

Expected outcome

After the ratios are updated, all three axes should become equal width:

Before: 0.3419
After: 0.2279

Image

Additional information

No response

Operating system

Ubuntu 24.04

Matplotlib Version

3.12.0.dev230+g1845e6647

Matplotlib Backend

tkagg

Python version

3.12.3

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions