FIX: when creating a canvas from a Figure use original dpi #30750
+10
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inCanvasBase.__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