fix: Fix unstable tkagg small plot size.#29989
Conversation
|
Thanks for the fix, it looks good to me. Could you add a comment in the code, since I don't think it's super obvious what |
How about this: tk.Frame.__init__(self, master=window, borderwidth=2,
width=int(canvas.figure.bbox.width), height=50)
+ # Avoid message_label expanding the toolbar size, and in turn expanding
+ # the canvas size. When the user defines a small figure size(e.g. 2x2),
+ # this will cause:
+ # 1. Figure size that is bigger than the user's expectation.
+ # 2. When message_label is refreshed by mouse enter/leave, the canvas
+ # size will also be changed.
self.pack_propagate(False) |
|
Basically yes. A bit clearer
|
4adcd17 to
185b4fa
Compare
|
Did we also want to shrink the toolbar height, as noted in #28330 (comment)? |
I'd be in favor of that. |
Sorry, I used to think this display issue was simply due to the height of the toolbar. When the scaling is set to 150% on windows, canvas is resized to 300 * 300, but the toolbar is resized to 300 * 50. This makes the appearance on Windows as expected, but not on Linux. I'm not very clear on how rescaling works with TkAgg. Does anyone have experience with this? |
|
I'm not an expert on this, but the relevant starting point in our code base is here: |
|
I can't reproduce the toolbar issue on Linux regardless of DPI scaling setting. I'm going to merge as this does fix a long-standing problem. |
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>


PR summary
Closes #28330 .
Before: Left After: Right
PR checklist