Title: Unexpected error after using Figure.canvas.draw on macosx backend · Issue #19197 · matplotlib/matplotlib · GitHub
Open Graph Title: Unexpected error after using Figure.canvas.draw on macosx backend · Issue #19197 · matplotlib/matplotlib
X Title: Unexpected error after using Figure.canvas.draw on macosx backend · Issue #19197 · matplotlib/matplotlib
Description: Bug report Bug summary It has been claimed that "fig.canvas.draw() is the canonical way to trigger a draw", replacing fig.draw(fig.canvas.get_renderer()). But on the macosx backend, this seems not to work. Code for reproduction import ma...
Open Graph Description: Bug report Bug summary It has been claimed that "fig.canvas.draw() is the canonical way to trigger a draw", replacing fig.draw(fig.canvas.get_renderer()). But on the macosx backend, this seems not ...
X Description: Bug report Bug summary It has been claimed that "fig.canvas.draw() is the canonical way to trigger a draw", replacing fig.draw(fig.canvas.get_renderer()). But on the macosx backend, this ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19197
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected error after using Figure.canvas.draw on macosx backend","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n**Bug summary**\r\n\r\nIt has [been claimed](https://github.com/matplotlib/matplotlib/issues/18407#issuecomment-687223797) that \"fig.canvas.draw() is the canonical way to trigger a draw\", replacing `fig.draw(fig.canvas.get_renderer())`. But on the macosx backend, this seems not to work.\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug.\r\nPlease make sure to minimize the number of dependencies required, and provide\r\nany necessary plotted data.\r\nAvoid using threads, as Matplotlib is (explicitly) not thread-safe.--\u003e\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nf, ax = plt.subplots()\r\nlines = ax.plot([0, 1])\r\nlegend = ax.legend(lines, [\"a line\"])\r\nf.canvas.draw()\r\n# f.draw(f.canvas.get_renderer())\r\nprint(legend.get_window_extent())\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n```python-traceback\r\nTraceback (most recent call last):\r\n File \"mpl_issue.py\", line 7, in \u003cmodule\u003e\r\n print(legend.get_window_extent())\r\n File \"/Users/mwaskom/miniconda3/lib/python3.7/site-packages/matplotlib/legend.py\", line 897, in get_window_extent\r\n return self._legend_box.get_window_extent(renderer=renderer)\r\n File \"/Users/mwaskom/miniconda3/lib/python3.7/site-packages/matplotlib/offsetbox.py\", line 346, in get_window_extent\r\n w, h, xd, yd, offsets = self.get_extent_offsets(renderer)\r\n File \"/Users/mwaskom/miniconda3/lib/python3.7/site-packages/matplotlib/offsetbox.py\", line 462, in get_extent_offsets\r\n dpicor = renderer.points_to_pixels(1.)\r\nAttributeError: 'NoneType' object has no attribute 'points_to_pixels'\r\n```\r\n\r\n**Expected outcome**\r\n\r\nOn the `qt5agg` backend, or when uncommenting the (deprecated?) `f.draw(f.canvas.get_renderer())` line, the code runs and prints the extent of the legend.\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Macos\r\n * Matplotlib version: 3.3.3\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): macosx\r\n * Python version: 3.8\r\n * Jupyter version (if applicable): na\r\n * Other libraries: \r\n\r\nxref https://github.com/matplotlib/matplotlib/issues/18407, https://github.com/mwaskom/seaborn/pull/2399\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n","author":{"url":"https://github.com/mwaskom","@type":"Person","name":"mwaskom"},"datePublished":"2020-12-29T21:17:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/19197/matplotlib/issues/19197"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f08f1d4f-2c80-504d-6a64-dae2f7eef38d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93C2:17596C:19A711C:2203912:6A51D42E |
| html-safe-nonce | 8fe660b5e7c3f7cc382a71541506e4c9b4d100e29e16205d4d878a466a042d5d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0MyOjE3NTk2QzoxOUE3MTFDOjIyMDM5MTI6NkE1MUQ0MkUiLCJ2aXNpdG9yX2lkIjoiNjk1OTk4MTQ1Njg0MTEwMjM4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9796edf993e0774f3380c7dd15044244a19f403cebbcd9b5b5e29970b6e320d6 |
| hovercard-subject-tag | issue:776091543 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/matplotlib/matplotlib/19197/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c2312aa38c32a054f84e07e152c506b1c4d1bc7e811aaa6d9c768c0a6035c8b/matplotlib/matplotlib/issues/19197 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c2312aa38c32a054f84e07e152c506b1c4d1bc7e811aaa6d9c768c0a6035c8b/matplotlib/matplotlib/issues/19197 |
| og:image:alt | Bug report Bug summary It has been claimed that "fig.canvas.draw() is the canonical way to trigger a draw", replacing fig.draw(fig.canvas.get_renderer()). But on the macosx backend, this seems not ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mwaskom |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width