Title: Remove internal use of `Artist.figure` by rcomer · Pull Request #28550 · matplotlib/matplotlib · GitHub
Open Graph Title: Remove internal use of `Artist.figure` by rcomer · Pull Request #28550 · matplotlib/matplotlib
X Title: Remove internal use of `Artist.figure` by rcomer · Pull Request #28550 · matplotlib/matplotlib
Description: PR summary The Artist.figure attribute is inconsistent: on most artists, it is the figure the artist is attached to, which may be a SubFigure. OTOH SubFigure.figure is always the root Figure. A lot of the internal usage of this attribute was written before subfigures existed, so there would not have been any decision to make about which figure is required. This means that in places we could be getting hold of a SubFigure when we really need a Figure. At #28177 (comment), @timhoffm said Internally, we should not be using figure anymore. so here is my attempt to remove that internal usage. If I comment out the figure property in both figure.py and artist.py, the tests still pass locally (except the one that explicitly tests the property). get_figure parameter choices Wherever I use get_figure in the main code, I made a choice about the root parameter. In many places, the end result will be the same whether root is True or False: artist.get_figure(root=False) will be None if and only if artist.get_figure(root=True) is None In many cases we are just accessing an attribute on the figure, which for a subfigure is the same as its parent, and therefore the same as the root. matplotlib/lib/matplotlib/figure.py Lines 2290 to 2297 in 830361d self._axstack = parent._axstack self.subplotpars = parent.subplotpars self.dpi_scale_trans = parent.dpi_scale_trans self._axobservers = parent._axobservers self.transFigure = parent.transFigure self.bbox_relative = Bbox.null() self._redo_transform_rel_fig() self.figbbox = self._parent.figbbox or accessing a property which returns the equivalent property of the parent matplotlib/lib/matplotlib/figure.py Lines 2310 to 2316 in 830361d @property def canvas(self): return self._parent.canvas @property def dpi(self): return self._parent.dpi or calling _get_renderer which calls _get_renderer on the parent matplotlib/lib/matplotlib/figure.py Lines 2339 to 2340 in 830361d def _get_renderer(self): return self._parent._get_renderer() For the above cases, I set root=False as that avoids the call to _parent_figure.get_figure within Artist.get_figure, so seems more efficient for most cases. matplotlib/lib/matplotlib/artist.py Lines 733 to 736 in 830361d if root and self._parent_figure is not None: return self._parent_figure.get_figure(root=True) return self._parent_figure For tests that do not involve subfigures, I left the root parameter out, because there is no ambiguity about what we are getting hold of and it would seem like unnecessary clutter. PR checklist [n/a] "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested [n/a] Plotting related features are demonstrated in an example [n/a] New Features and API Changes are noted with a directive and release note [n/a] Documentation complies with general and docstring guidelines
Open Graph Description: PR summary The Artist.figure attribute is inconsistent: on most artists, it is the figure the artist is attached to, which may be a SubFigure. OTOH SubFigure.figure is always the root Figure. A l...
X Description: PR summary The Artist.figure attribute is inconsistent: on most artists, it is the figure the artist is attached to, which may be a SubFigure. OTOH SubFigure.figure is always the root Figure. A l...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/28550
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3f3d08cd-4ce0-8946-a673-4f6fc8093452 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DD46:152AB4:5AB01F:795548:6A52FC9C |
| html-safe-nonce | 0ae6e8a38dcc4b0bc8ada7c977dcde318cf2428b80242d2a06f0e72a896afcc9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDQ2OjE1MkFCNDo1QUIwMUY6Nzk1NTQ4OjZBNTJGQzlDIiwidmlzaXRvcl9pZCI6IjUzMjE3MzE3MzE1NzI4NDk4MjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 862ade083e97306bc0f728db85b64d1aa855ae7d72d450c514bba54ccbf46fb6 |
| hovercard-subject-tag | pull_request:1966660349 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/28550/files |
| twitter:image | https://avatars.githubusercontent.com/u/10599679?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/10599679?s=400&v=4 |
| og:image:alt | PR summary The Artist.figure attribute is inconsistent: on most artists, it is the figure the artist is attached to, which may be a SubFigure. OTOH SubFigure.figure is always the root Figure. A l... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width