🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@tacaswell
Copy link
Member

PR summary

When we upscale the DPI for high-dpi screens we stash the original dpi and then set the figure dpi to the scaled version. If the same Figure instance is repeatedly passed to a Canvas that support hi-dpi it would go into a loop where the scaled DPI is treated as the original dpi and infinitely increases.

By grabbing fig._original_dpi (which we stash for exactly this reason) we can avoid this loop.

closes #26380

This is a slightly more general version of what we had already done to support re-attaching Figures to pyplot.

This is covered by the tests for dpi ratio tests we added as part of re-attaching to Figures to pyplot (which my first version of this broke so I'm sure it is being hit).

There is a case that we should move the "re run with device ratio 1" logic into CanvasBase, but any backend that does support scaling will take care of re-scaling the canvas on display so setting it back to 1 in CanvasBase.__init__ seems like it will always be redundent for users and we have a hook to explicitly clean it up when we remove the Figure from pyplot.

I suspect there is still a few more iterations before we have covered all the stress-cases on this, but this is another step in the right direction.

PR checklist

When we upscale the DPI for high-dpi screens we stash the original dpi and then
set the figure dpi to the scaled version.  If the same Figure instance is
repeatedly passed to a Canvas that support hi-dpi it would go into a loop where
the scaled DPI is treated as the original dpi and infinitely increases.

By grabbing `fig._original_dpi` (which we stash for exactly this reason) we can
avoid this loop.

closes matplotlib#26380
@anntzer
Copy link
Contributor

anntzer commented Nov 13, 2025

Maybe related to #27224? (I didn't actually check)

The issue is that we reset the dpi but did not re-compute any of the
bounding boxes derived from the dpi leading to the initial redraw events
to use the wrong physical size on the screen.

Closes matplotlib#27224
@tacaswell
Copy link
Member Author

I found a clean place to test the second fix.

@ksunden ksunden merged commit 94055bc into matplotlib:main Dec 11, 2025
66 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DPI keeps doubling when creating a new MatPlotLib QtWidget in qt6

5 participants