Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0041fb

Browse files
committed
FIX: when creating a canvas from a Figure use original dpi
When we upscale the DPI for high-dpi screens we stash the original dpi and thenset the figure dpi to the scaled version. If the same Figure instance isrepeatedly passed to a Canvas that support hi-dpi it would go into a loop wherethe scaled DPI is treated as the original dpi and infinitely increases.By grabbing `fig._original_dpi` (which we stash for exactly this reason) we canavoid this loop.closes#26380
1 parent1ab3332 commitc0041fb

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

‎lib/matplotlib/backend_bases.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ def __init__(self, figure=None):
17631763
self.toolbar=None# NavigationToolbar2 will set me
17641764
self._is_idle_drawing=False
17651765
# We don't want to scale up the figure DPI more than once.
1766-
figure._original_dpi=figure.dpi
1766+
figure._original_dpi=getattr(figure,'_original_dpi',figure.dpi)
17671767
self._device_pixel_ratio=1
17681768
super().__init__()# Typically the GUI widget init (if any).
17691769

‎lib/matplotlib/figure.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,12 +3003,10 @@ def _set_base_canvas(self):
30033003
This is used upon initialization of the Figure, but also
30043004
to reset the canvas when decoupling from pyplot.
30053005
"""
3006-
# check if we have changed the DPI due to hi-dpi screens
3007-
orig_dpi=getattr(self,'_original_dpi',self._dpi)
30083006
FigureCanvasBase(self)# Set self.canvas as a side-effect
3009-
#put it back to what it was
3010-
iforig_dpi!=self._dpi:
3011-
self.dpi=orig_dpi
3007+
#undo any high-dpi scaling
3008+
ifself._dpi!=self._original_dpi:
3009+
self.dpi=self._original_dpi
30123010

30133011
defset_canvas(self,canvas):
30143012
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp