Skip to content

Commit 185b4fa

Browse files
committed
fix: Fix unstable tkagg small plot size.
1 parent 4af11e7 commit 185b4fa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,14 @@ def __init__(self, canvas, window=None, *, pack_toolbar=True):
638638
window = canvas.get_tk_widget().master
639639
tk.Frame.__init__(self, master=window, borderwidth=2,
640640
width=int(canvas.figure.bbox.width), height=50)
641+
# Avoid message_label expanding the toolbar size, and in turn expanding the
642+
# canvas size.
643+
# Without pack_propagate(False), when the user defines a small figure size
644+
# (e.g. 2x2):
645+
# 1. Figure size that is bigger than the user's expectation.
646+
# 2. When message_label is refreshed by mouse enter/leave, the canvas
647+
# size will also be changed.
648+
self.pack_propagate(False)
641649

642650
self._buttons = {}
643651
for text, tooltip_text, image_file, callback in self.toolitems:

0 commit comments

Comments
 (0)