Title: tight_layout relies on get_renderer, which is not available on all backends · Issue #1852 · matplotlib/matplotlib · GitHub
Open Graph Title: tight_layout relies on get_renderer, which is not available on all backends · Issue #1852 · matplotlib/matplotlib
X Title: tight_layout relies on get_renderer, which is not available on all backends · Issue #1852 · matplotlib/matplotlib
Description: With the MacOSX backend and possibly other backends, tight_layout falls back to the Agg backend. For example, demo_tight_layout.py does the following: $ python -i examples/pylab_examples/demo_tight_layout.py /Library/Frameworks/Python.fr...
Open Graph Description: With the MacOSX backend and possibly other backends, tight_layout falls back to the Agg backend. For example, demo_tight_layout.py does the following: $ python -i examples/pylab_examples/demo_tight...
X Description: With the MacOSX backend and possibly other backends, tight_layout falls back to the Agg backend. For example, demo_tight_layout.py does the following: $ python -i examples/pylab_examples/demo_tight...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/1852
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tight_layout relies on get_renderer, which is not available on all backends","articleBody":"With the MacOSX backend and possibly other backends, tight_layout falls back to the Agg backend. For example, demo_tight_layout.py does the following:\n\n$ python -i examples/pylab_examples/demo_tight_layout.py\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.6-intel.egg/matplotlib/tight_layout.py:225: UserWarning: tight_layout : falling back to Agg renderer\n warnings.warn(\"tight_layout : falling back to Agg renderer\")\n\nThis is the relevant code in tight_layout.py:\n\n```\ndef get_renderer(fig):\n if fig._cachedRenderer:\n renderer = fig._cachedRenderer\n else:\n canvas = fig.canvas \n if canvas and hasattr(canvas, \"get_renderer\"):\n renderer = canvas.get_renderer()\n else:\n # not sure if this can happen\n warnings.warn(\"tight_layout : falling back to Agg renderer\")\n from matplotlib.backends.backend_agg import FigureCanvasAgg\n canvas = FigureCanvasAgg(fig)\n renderer = canvas.get_renderer()\n return renderer\n```\n\nNeither backend_template.py nor backend_bases.py implement a get_renderer method, nor do the MacOSX and gtkcairo backend (and possibly other backends). \n\nEven if I were to add a get_renderer method to the canvas in the MacOSX backend, this still fails. The problem is that this code tries to grab a renderer and use it outside of the event loop (i.e., outside of the figure.draw method). Outside of the event loop, the graphics context is not defined, and the code fails as follows:\n\n$ python -i examples/pylab_examples/demo_tight_layout.py\nTraceback (most recent call last):\nFile \"examples/pylab_examples/demo_tight_layout.py\", line 15, in\nplt.tight_layout()\n...\nRuntimeError: CGContextRef is NULL\n\nI would suggest to restructure the code in tight_layout.py to avoid using the renderer directly.\n","author":{"url":"https://github.com/mdehoon","@type":"Person","name":"mdehoon"},"datePublished":"2013-03-24T10:21:18.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":20},"url":"https://github.com/1852/matplotlib/issues/1852"}
| 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:a1993340-88dd-1e48-2290-28c06e79a385 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A65C:1BD726:20B3E9E:2BA072D:6A54614F |
| html-safe-nonce | a8c04e26d8e21bced3e217716a116d72d6a4272292a8d2dc6ce4ebd329b97aa9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjVDOjFCRDcyNjoyMEIzRTlFOjJCQTA3MkQ6NkE1NDYxNEYiLCJ2aXNpdG9yX2lkIjoiNzY5MzQ2NTg2NTU5NDEwMjA5NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 08aab1d08d8c58654c03220eb40f12e1a8aeae036e858ee9713b929c0575a434 |
| hovercard-subject-tag | issue:12371687 |
| 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/1852/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d6ef6d06ab2f450ecddd0952c296d700686abb0c13393b28b51e886e1047a02a/matplotlib/matplotlib/issues/1852 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d6ef6d06ab2f450ecddd0952c296d700686abb0c13393b28b51e886e1047a02a/matplotlib/matplotlib/issues/1852 |
| og:image:alt | With the MacOSX backend and possibly other backends, tight_layout falls back to the Agg backend. For example, demo_tight_layout.py does the following: $ python -i examples/pylab_examples/demo_tight... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mdehoon |
| 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 | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width