Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add get/set methods for DPI in SubFigure #23276

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,23 @@ def dpi(self):
def dpi(self, value):
self._parent.dpi = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a self.stale = True here? (For symmetry with set_dpi?)

(Maybe not a question for you @scottjones03 though.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but in practice the parent will catch this and trigger the required re-draw.


def get_dpi(self):
"""
Return the resolution of the parent figure in dots-per-inch as a float.
"""
return self._parent.dpi

def set_dpi(self, val):
"""
Set the resolution of parent figure in dots-per-inch.

Parameters
----------
val : float
"""
self._parent.dpi = val
self.stale = True

def _get_renderer(self):
return self._parent._get_renderer()

Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,16 @@ def test_subfigure_tightbbox():
8.0)


def test_subfigure_dpi():
fig = plt.figure(dpi=100)
sub_fig = fig.subfigures()
assert sub_fig.get_dpi() == fig.get_dpi()

sub_fig.set_dpi(200)
assert sub_fig.get_dpi() == 200
assert fig.get_dpi() == 200


@image_comparison(['test_subfigure_ss.png'], style='mpl20',
savefig_kwarg={'facecolor': 'teal'})
def test_subfigure_ss():
Expand Down