Skip to content

Commit 7bafb8b

Browse files
authored
Deprecate internal use of get/set dpi
1 parent 37cf8e4 commit 7bafb8b

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-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
if self._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
if self._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
@@ -2758,8 +2758,8 @@ def get_default_filetype(self):
27582758
def print_pdf(self, filename, *,
27592759
bbox_inches_restore=None, metadata=None):
27602760

2761-
dpi = self.figure.get_dpi()
2762-
self.figure.set_dpi(72) # there are 72 pdf points to an inch
2761+
dpi = self.figure.dpi
2762+
self.figure.dpi = 72 # there are 72 pdf points to an inch
27632763
width, height = self.figure.get_size_inches()
27642764
if isinstance(filename, PdfPages):
27652765
file = filename._file

lib/matplotlib/backends/backend_pgf.py

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

813813
# get figure size in inch
814814
w, h = self.figure.get_figwidth(), self.figure.get_figheight()
815-
dpi = self.figure.get_dpi()
815+
dpi = self.figure.dpi
816816

817817
# create pgfpicture environment and write the pgf code
818818
fh.write(header_text)

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ def _print_ps(
833833
metadata=None, papertype=None, orientation='portrait',
834834
**kwargs):
835835

836-
dpi = self.figure.get_dpi()
837-
self.figure.set_dpi(72) # Override the dpi kwarg
836+
dpi = self.figure.dpi
837+
self.figure.dpi = 72 # Override the dpi kwarg
838838

839839
dsc_comments = {}
840840
if isinstance(outfile, (str, os.PathLike)):

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,8 +1335,8 @@ def print_svg(self, filename, *args, bbox_inches_restore=None,
13351335
with cbook.open_file_cm(filename, "w", encoding="utf-8") as fh:
13361336
if not cbook.file_requires_unicode(fh):
13371337
fh = codecs.getwriter('utf-8')(fh)
1338-
dpi = self.figure.get_dpi()
1339-
self.figure.set_dpi(72)
1338+
dpi = self.figure.dpi
1339+
self.figure.dpi = 72
13401340
width, height = self.figure.get_size_inches()
13411341
w, h = width * 72, height * 72
13421342
renderer = MixedModeRenderer(

lib/matplotlib/tests/test_figure.py

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

591591
@check_figures_equal(extensions=["png", "pdf"])
592592
def test_add_artist(fig_test, fig_ref):
593-
fig_test.set_dpi(100)
594-
fig_ref.set_dpi(100)
593+
fig_test.dpi = 100
594+
fig_ref.dpi = 100
595595

596596
fig_test.subplots()
597597
l1 = plt.Line2D([.2, .7], [.7, .7], gid='l1')
@@ -1222,10 +1222,10 @@ def test_subfigure_ticks():
12221222
ax2.scatter(x=[-126.5357270050049, 94.68456736755368], y=[1500, 3600])
12231223
ax3 = subfig_bl.add_subplot(gs[0, 3:14], sharey=ax1)
12241224

1225-
fig.set_dpi(120)
1225+
fig.dpi = 120
12261226
fig.draw_without_rendering()
12271227
ticks120 = ax2.get_xticks()
1228-
fig.set_dpi(300)
1228+
fig.dpi = 300
12291229
fig.draw_without_rendering()
12301230
ticks300 = ax2.get_xticks()
12311231
np.testing.assert_allclose(ticks120, ticks300)

lib/matplotlib/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,13 +1503,13 @@ def _get_xy_transform(self, renderer, s):
15031503
ref_x, ref_y = xy0
15041504
if unit == "points":
15051505
# dots per points
1506-
dpp = self.figure.get_dpi() / 72.
1506+
dpp = self.figure.dpi / 72.
15071507
tr = Affine2D().scale(dpp)
15081508
elif unit == "pixels":
15091509
tr = Affine2D()
15101510
elif unit == "fontsize":
15111511
fontsize = self.get_size()
1512-
dpp = fontsize * self.figure.get_dpi() / 72.
1512+
dpp = fontsize * self.figure.dpi / 72.
15131513
tr = Affine2D().scale(dpp)
15141514
elif unit == "fraction":
15151515
w, h = bbox0.size

0 commit comments

Comments
 (0)