8000 Merge pull request #15045 from dstansby/qt5-fig-size · jklymak/matplotlib@8df7fe1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8df7fe1

Browse files
authored
Merge pull request matplotlib#15045 from dstansby/qt5-fig-size
Resize canvas when changing figure size
2 parents bedb4d9 + 1d7bbf9 commit 8df7fe1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ def resize(self, width, height):
622622
# so we do not need to worry about dpi scaling here.
623623
extra_width = self.window.width() - self.canvas.width()
624624
extra_height = self.window.height() - self.canvas.height()
625-
self.window.resize(width+extra_width, height+extra_height)
625+
self.canvas.resize(width, height)
626+
self.window.resize(width + extra_width, height + extra_height)
626627

627628
def show(self):
628629
self.window.show()

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import matplotlib
66
from matplotlib import pyplot as plt
7+
from matplotlib import rcParams
78
from matplotlib._pylab_helpers import Gcf
89

910
import pytest
@@ -272,3 +273,23 @@ def test_figureoptions():
272273
"matplotlib.backends.qt_editor._formlayout.FormDialog.exec_",
273274
lambda self: None):
274275
fig.canvas.manager.toolbar.edit_parameters()
276+
277+
278+
@pytest.mark.backend('Qt5Agg')
279+
def test_double_resize():
280+
# Check that resizing a figure twice keeps the same window size
281+
fig, ax = plt.subplots()
282+
fig.canvas.draw()
283+
window = fig.canvas.manager.window
284+
285+
w, h = 3, 2
286+
fig.set_size_inches(w, h)
287+
assert fig.canvas.width() == w * rcParams['figure.dpi']
288+
assert fig.canvas.height() == h * rcParams['figure.dpi']
289+
290+
old_width = window.width()
291+
old_height = window.height()
292+
293+
fig.set_size_inches(w, h)
294+
assert window.width() == old_width
295+
assert window.height() == old_height

0 commit comments

Comments
 (0)
0