Skip to content

Commit 5cd30d2

Browse files
committed
Resize canvas when changing figures size in Qt5Agg
1 parent 662bb8c commit 5cd30d2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ def resize(self, width, height):
631631
# so we do not need to worry about dpi scaling here.
632632
extra_width = self.window.width() - self.canvas.width()
633633
extra_height = self.window.height() - self.canvas.height()
634-
self.window.resize(width+extra_width, height+extra_height)
634+
self.canvas.resize(width, height)
635+
self.window.resize(width + extra_width, height + extra_height)
635636

636637
def show(self):
637638
self.window.show()

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,19 @@ def test_figureoptions():
272272
"matplotlib.backends.qt_editor._formlayout.FormDialog.exec_",
273273
lambda self: None):
274274
fig.canvas.manager.toolbar.edit_parameters()
275+
276+
277+
@pytest.mark.backend('Qt5Agg')
278+
def test_double_resize():
279+
# Check that resizing a figure twice keeps the same window size
280+
fig, ax = plt.subplots()
281+
fig.canvas.draw()
282+
window = fig.canvas.manager.window
283+
284+
fig.set_size_inches(2, 2)
285+
old_width = window.width()
286+
old_height = window.height()
287+
288+
fig.set_size_inches(2, 2)
289+
assert window.width() == old_width
290+
assert window.height() == old_height

0 commit comments

Comments
 (0)