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

Skip to content

[MNT]: set_dpi and get_dpi functions defined twice in figure.py #29909

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

Closed
Guzzelius opened this issue Apr 12, 2025 · 1 comment
Closed

[MNT]: set_dpi and get_dpi functions defined twice in figure.py #29909

Guzzelius opened this issue Apr 12, 2025 · 1 comment

Comments

@Guzzelius
Copy link

Summary

Hey,

I just stumbled over the fact that the methods 'set_dpi' and 'get_dpi' are defined twice in figure.py (first in lines 2257 foolwing and then in lines 3084 following:

They apear also twice in figure.pyi, once with the type: float and once without:
289: def get_dpi(self) -> float: ...
290: def set_dpi(self, val) -> None: ...
vs:
372: def get_dpi(self) -> float: ...
373: def set_dpi(self, val: float) -> None: ...

Maybe I am a noob and there is good reason, if not it should be cleaned up.

Proposed fix

If no good reason, delete one of them.

@tacaswell
Copy link
Member

Thank you for looking at this, however it is my understanding that we need both versions of the functions.

Looking at the code,

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

and

def get_dpi(self):
"""Return the resolution in dots per inch as a float."""
return self.dpi
def set_dpi(self, val):
"""
Set the resolution of the figure in dots-per-inch.
Parameters
----------
val : float
"""
self.dpi = val
self.stale = True

are on different classes (the first is on SubFigure and the second is on Figure) so these implementations do not over-ride each other. Somewhat surprisingly from the names and how the instances are nested, Figure and SubFigure are siblings with a common base class (FigureBase). Because SubFigure instances are always contained in a Figure and Figure instances are always the top of the artist tree, we can not have a shared version on the base class (the Figure owns the truth of what the dpi is and SubFigures need to track that).


The SubFigure versions were added in e12db8d / #23276 to fix pdf writing.

@tacaswell tacaswell closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants