-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rationalise artist get_figure methods; make figure attribute a property #28177
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(Sub)Figure.get_figure | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
...in future will by default return the direct parent figure, which may be a SubFigure. | ||
This will make the default behavior consistent with the | ||
`~matplotlib.artist.Artist.get_figure` method of other artists. To control the | ||
behavior, use the newly introduced *root* parameter. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(Sub)Figure.set_figure | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
...is deprecated and in future will always raise an exception. The parent and | ||
root figures of a (Sub)Figure are set at instantiation and cannot be changed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,8 @@ class FigureBase(Artist): | |
) -> dict[Hashable, Axes]: ... | ||
|
||
class SubFigure(FigureBase): | ||
figure: Figure | ||
@property | ||
def figure(self) -> Figure: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ksunden can you advise what I should do here? It is a fact of the implementation that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firstly, the allow list is only for Secondly, is there a reason to be more strict here? Subfigures can be nested inside of subfigures, can they not? Type narrowing for a subclass isn't actually the problem here, but also not clear to me why it is narrowed here. (Not fully sure why you get two errors for each... but both are resolved below without adjusting their own type hints...) Unfortunately, getting rid of the setter is breaking a pretty fundamental Object Orientation principle that all things that are provided by the parent class can be done on instances of child classes... and the method still exists, so I think type hinting it is fine... That said, I would not be too opposed to making If I comment out the two lines from diff --git a/lib/matplotlib/artist.pyi b/lib/matplotlib/artist.pyi
index 08a99c0ed1..730c530dd2 100644
--- a/lib/matplotlib/artist.pyi
+++ b/lib/matplotlib/artist.pyi
@@ -33,8 +33,8 @@ class Artist:
stale_callback: Callable[[Artist, bool], None] | None
@property
def figure(self) -> Figure | SubFigure: ...
- @figure.setter
- def figure(self, fig: Figure | SubFigure): ...
+ #@figure.setter
+ #def figure(self, fig: Figure | SubFigure): ...
clipbox: BboxBase | None
def __init__(self) -> None: ...
def remove(self) -> None: ... In implementation, Also, looking back... the type hint is technically wrong, as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re type narrowing, I guess actually closely reading the code, you do narrow, so not opposed to encapsulating that meaning if that is what the code does... but do have some slight hesitations there, particularly if standard artists don't get root for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunately we have a mismatch in what this property is: [slow x-post] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #28170 (comment) suggested discouraging use of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The motivation for moving from I'm not clear what the effect of not type-hinting is. Would it not show up in completions? Would there be warnings on incomplete typing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm (clearly!) no expert on type hinting but I took out the hint for this property in my branch and the mypy-precommit flagged failures in
Should internal usage be removed in this PR or could it wait for a follow-up? I lean towards doing it separately as I think the current change stands by itself and should be useful for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, the internal refactoring can be a follow-up.
That's part of the motivation to get rid of it 😏. I also won't guarantee that the current usages are always correct. Subfigures (and in particular nested subfigures) are fairly recent and thus not that common. |
||
subplotpars: SubplotParams | ||
dpi_scale_trans: Affine2D | ||
transFigure: Transform | ||
|
@@ -298,7 +299,8 @@ class SubFigure(FigureBase): | |
def get_axes(self) -> list[Axes]: ... | ||
|
||
class Figure(FigureBase): | ||
figure: Figure | ||
@property | ||
def figure(self) -> Figure: ... | ||
bbox_inches: Bbox | ||
dpi_scale_trans: Affine2D | ||
bbox: BboxBase | ||
|
Uh oh!
There was an error while loading. Please reload this page.