Skip to content

fix: Fix unstable tkagg small plot size. #29989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sandyowlet
Copy link
Contributor

PR summary

Closes #28330 .

image
Before: Left After: Right

417524558-869502a2-fd5e-4343-b741-2a7f237e5c1c

PR checklist

@sandyowlet sandyowlet closed this Apr 30, 2025
@sandyowlet sandyowlet deleted the bugfix/issue-28330 branch April 30, 2025 06:13
@sandyowlet sandyowlet restored the bugfix/issue-28330 branch April 30, 2025 06:18
@sandyowlet sandyowlet reopened this Apr 30, 2025
@dstansby
Copy link
Member

dstansby commented May 5, 2025

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 pack_propagate() is achieving here. Something like # Don't resize the toolbar when mouse coordinates are shown or not shown.

@dstansby dstansby modified the milestones: v3.10.2, v3.10.3 May 5, 2025
@sandyowlet
Copy link
Contributor Author

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 pack_propagate() is achieving here. Something like # Don't resize the toolbar when mouse coordinates are shown or not shown.

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)

@timhoffm
Copy link
Member

timhoffm commented May 8, 2025

Basically yes. A bit clearer

... Without pack_propergate(False), when the user defines a small figure size(e.g. 2x2),

@sandyowlet sandyowlet force-pushed the bugfix/issue-28330 branch from 4adcd17 to 185b4fa Compare May 9, 2025 16:45
@QuLogic
Copy link
Member

QuLogic commented May 9, 2025

Did we also want to shrink the toolbar height, as noted in #28330 (comment)?

@timhoffm
Copy link
Member

Did we also want to shrink the toolbar height, as noted in #28330 (comment)?

I'd be in favor of that.

@sandyowlet
Copy link
Contributor Author

sandyowlet commented May 19, 2025

Did we also want to shrink the toolbar height, as noted in #28330 (comment)?

Sorry, I used to think this display issue was simply due to the height of the toolbar.
However, after testing in both Windows and Linux environments, it seems to be related to DPI scaling.

(windows)
image

(linux)
image

When the scaling is set to 150% on windows, canvas is resized to 300 * 300, but the toolbar is resized to 300 * 50.
And on linux, the canvas is resized to 300 * 300 and toolbar is resized to 300 * 75.

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?

@timhoffm
Copy link
Member

I'm not an expert on this, but the relevant starting point in our code base is here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: unstable tkagg small plot size window
4 participants