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

Commit56b0ad4

Browse files
authored
Merge pull request#23338 from tacaswell/auto-backport-of-pr-23278-on-v3.5.x
Backport PR#23278: Remove internal use of get/set dpi
2 parents16e8a7a +b474ee0 commit56b0ad4

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

‎lib/matplotlib/backends/backend_mixed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, figure, width, height, dpi, vector_renderer,
5353
# the figure dpi before and after the rasterization. Although
5454
# this looks ugly, I couldn't find a better solution. -JJL
5555
self.figure=figure
56-
self._figdpi=figure.get_dpi()
56+
self._figdpi=figure.dpi
5757

5858
self._bbox_inches_restore=bbox_inches_restore
5959

@@ -74,7 +74,7 @@ def start_rasterizing(self):
7474
`stop_rasterizing` is called) will be drawn with the raster backend.
7575
"""
7676
# change the dpi of the figure temporarily.
77-
self.figure.set_dpi(self.dpi)
77+
self.figure.dpi=self.dpi
7878
ifself._bbox_inches_restore:# when tight bbox is used
7979
r=process_figure_for_rasterizing(self.figure,
8080
self._bbox_inches_restore)
@@ -110,7 +110,7 @@ def stop_rasterizing(self):
110110
self._raster_renderer=None
111111

112112
# restore the figure dpi.
113-
self.figure.set_dpi(self._figdpi)
113+
self.figure.dpi=self._figdpi
114114

115115
ifself._bbox_inches_restore:# when tight bbox is used
116116
r=process_figure_for_rasterizing(self.figure,

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,8 +2774,8 @@ def print_pdf(self, filename, *,
27742774
bbox_inches_restore=None,metadata=None):
27752775

27762776
ifdpiisNone:# always use this branch after deprecation elapses.
2777-
dpi=self.figure.get_dpi()
2778-
self.figure.set_dpi(72)# there are 72 pdf points to an inch
2777+
dpi=self.figure.dpi
2778+
self.figure.dpi=72# there are 72 pdf points to an inch
27792779
width,height=self.figure.get_size_inches()
27802780
ifisinstance(filename,PdfPages):
27812781
file=filename._file

‎lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def _print_pgf_to_fh(self, fh, *, bbox_inches_restore=None):
826826

827827
# get figure size in inch
828828
w,h=self.figure.get_figwidth(),self.figure.get_figheight()
829-
dpi=self.figure.get_dpi()
829+
dpi=self.figure.dpi
830830

831831
# create pgfpicture environment and write the pgf code
832832
fh.write(header_text)

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ def _print_ps(
853853
**kwargs):
854854

855855
ifdpiisNone:# always use this branch after deprecation elapses.
856-
dpi=self.figure.get_dpi()
857-
self.figure.set_dpi(72)# Override the dpi kwarg
856+
dpi=self.figure.dpi
857+
self.figure.dpi=72# Override the dpi kwarg
858858

859859
dsc_comments= {}
860860
ifisinstance(outfile, (str,os.PathLike)):

‎lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,8 @@ def print_svg(self, filename, *args, dpi=None, bbox_inches_restore=None,
13221322
ifnotcbook.file_requires_unicode(fh):
13231323
fh=codecs.getwriter('utf-8')(fh)
13241324
ifdpiisNone:# always use this branch after deprecation elapses
1325-
dpi=self.figure.get_dpi()
1326-
self.figure.set_dpi(72)
1325+
dpi=self.figure.dpi
1326+
self.figure.dpi=72
13271327
width,height=self.figure.get_size_inches()
13281328
w,h=width*72,height*72
13291329
renderer=MixedModeRenderer(

‎lib/matplotlib/tests/test_figure.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ def test_invalid_layouts():
602602

603603
@check_figures_equal(extensions=["png","pdf"])
604604
deftest_add_artist(fig_test,fig_ref):
605-
fig_test.set_dpi(100)
606-
fig_ref.set_dpi(100)
605+
fig_test.dpi=100
606+
fig_ref.dpi=100
607607

608608
fig_test.subplots()
609609
l1=plt.Line2D([.2,.7], [.7,.7],gid='l1')
@@ -1237,10 +1237,10 @@ def test_subfigure_ticks():
12371237
ax2.scatter(x=[-126.5357270050049,94.68456736755368],y=[1500,3600])
12381238
ax3=subfig_bl.add_subplot(gs[0,3:14],sharey=ax1)
12391239

1240-
fig.set_dpi(120)
1240+
fig.dpi=120
12411241
fig.draw_without_rendering()
12421242
ticks120=ax2.get_xticks()
1243-
fig.set_dpi(300)
1243+
fig.dpi=300
12441244
fig.draw_without_rendering()
12451245
ticks300=ax2.get_xticks()
12461246
np.testing.assert_allclose(ticks120,ticks300)
@@ -1263,6 +1263,16 @@ def test_subfigure_scatter_size():
12631263
ax.scatter([3,4,5], [1,2,3],s=[20,30,40],marker='s',color='g')
12641264

12651265

1266+
deftest_subfigure_pdf():
1267+
fig=plt.figure(layout='constrained')
1268+
sub_fig=fig.subfigures()
1269+
ax=sub_fig.add_subplot(111)
1270+
b=ax.bar(1,1)
1271+
ax.bar_label(b)
1272+
buffer=io.BytesIO()
1273+
fig.savefig(buffer,format='pdf')
1274+
1275+
12661276
deftest_add_subplot_kwargs():
12671277
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
12681278
fig=plt.figure()

‎lib/matplotlib/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,13 +1486,13 @@ def _get_xy_transform(self, renderer, s):
14861486
ref_x,ref_y=xy0
14871487
ifunit=="points":
14881488
# dots per points
1489-
dpp=self.figure.get_dpi()/72.
1489+
dpp=self.figure.dpi/72
14901490
tr=Affine2D().scale(dpp)
14911491
elifunit=="pixels":
14921492
tr=Affine2D()
14931493
elifunit=="fontsize":
14941494
fontsize=self.get_size()
1495-
dpp=fontsize*self.figure.get_dpi()/72.
1495+
dpp=fontsize*self.figure.dpi/72
14961496
tr=Affine2D().scale(dpp)
14971497
elifunit=="fraction":
14981498
w,h=bbox0.size

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp