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

FIX: when creating a canvas from a Figure use original dpi#30750

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tacaswell wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromtacaswell:fix_hidpi_loop
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionlib/matplotlib/backend_bases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1763,7 +1763,7 @@ def __init__(self, figure=None):
self.toolbar = None # NavigationToolbar2 will set me
self._is_idle_drawing = False
# We don't want to scale up the figure DPI more than once.
figure._original_dpi = figure.dpi
figure._original_dpi =getattr(figure, '_original_dpi', figure.dpi)
self._device_pixel_ratio = 1
super().__init__() # Typically the GUI widget init (if any).

Expand Down
13 changes: 6 additions & 7 deletionslib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3003,12 +3003,10 @@ def _set_base_canvas(self):
This is used upon initialization of the Figure, but also
to reset the canvas when decoupling from pyplot.
"""
# check if we have changed the DPI due to hi-dpi screens
orig_dpi = getattr(self, '_original_dpi', self._dpi)
FigureCanvasBase(self) # Set self.canvas as a side-effect
#put it back to what it was
iforig_dpi != self._dpi:
self.dpi =orig_dpi
#undo any high-dpi scaling
ifself._dpi != self._original_dpi:
self.dpi =self._original_dpi

def set_canvas(self, canvas):
"""
Expand DownExpand Up@@ -3323,8 +3321,9 @@ def __setstate__(self, state):
self.__dict__ = state

# re-initialise some of the unstored state information
FigureCanvasBase(self) # Set self.canvas.

self._set_base_canvas()
# force the bounding boxes to respect current dpi
self.dpi_scale_trans.clear().scale(self._dpi)
if restore_to_pylab:
# lazy import to avoid circularity
import matplotlib.pyplot as plt
Expand Down
3 changes: 3 additions & 0 deletionslib/matplotlib/tests/test_figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1688,6 +1688,9 @@ def test_unpickle_with_device_pixel_ratio():
assert fig.dpi == 42*7
fig2 = pickle.loads(pickle.dumps(fig))
assert fig2.dpi == 42
assert all(
[orig / 7 == restore for orig, restore in zip(fig.bbox.max, fig2.bbox.max)]
)


def test_gridspec_no_mutate_input():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp