Skip to content

[Bug]: Figure does not scale to window size #22822

Open
@thomas-haslwanter

Description

@thomas-haslwanter

Bug summary

When changing the window size of a figure, the figure does not scale immediately, so part of it is obscured. Only after a manual re-scaling (even if minute) the figure is displayed correctly.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

# Generate some data
t = np.arange(0, 10, 0.1)
x = np.cos(t)

fig, ax = plt.subplots(1,1)

# Put the figure in the top-left half of the screen
cur_win = fig.canvas.manager.window     # Current window
screen_size = cur_win.wm_maxsize()      # Get the screen size
# top-left half of the window:
(pos_x, pos_y, width, height) = (0, 0, screen_size[0]//2, screen_size[1]//2)
position = f'{width}x{height}+{pos_x}+{pos_y}'  # Window geometry string
cur_win.geometry(position)

ax.plot(t, x)
plt.show()

Actual outcome

scaling_problem_01

Expected outcome

When the size of the window is then MANUALLY changed, the figure immediately changes to the accurate scale:
scaling_problem_02

Additional information

The bug appears from Matplotlib 3.5.1 onward

Operating system

Windows 11

Matplotlib Version

3.5.1

Matplotlib Backend

TkAgg

Python version

3.9.10

Jupyter version

No response

Installation

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions