Title: [Doc]: How to replicate behaviour of `plt.gca(projection=...)`? · Issue #20770 · matplotlib/matplotlib · GitHub
Open Graph Title: [Doc]: How to replicate behaviour of `plt.gca(projection=...)`? · Issue #20770 · matplotlib/matplotlib
X Title: [Doc]: How to replicate behaviour of `plt.gca(projection=...)`? · Issue #20770 · matplotlib/matplotlib
Description: Documentation Link https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot Problem In version 3.4, passing keyword arguments to plt.gca() was deprecated. I was previously u...
Open Graph Description: Documentation Link https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot Problem In version 3.4, passing keyword arguments to plt....
X Description: Documentation Link https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot Problem In version 3.4, passing keyword arguments to plt....
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/20770
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Doc]: How to replicate behaviour of `plt.gca(projection=...)`?","articleBody":"### Documentation Link\n\nhttps://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot\n\n### Problem\n\nIn version 3.4, passing keyword arguments to `plt.gca()` was deprecated. I was previously using `plt.gca(projection='polar')` to:\r\n\r\n1. Check if a polar projection axes exists, and if so return it\r\n2. If not, create a new axes with a polar projection\r\n\r\nLooking at the documentation (https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot) it's not clear to me how to replicate this behaviour however. In pseudo-code I think what I want to do is:\r\n```python\r\nif len(pyplot_axes):\r\n if plt.gca().name != 'polar':\r\n raise RuntimeError('Axes isn't polar projection')\r\n else:\r\n return plt.gca()\r\nelse:\r\n return plt.subplot(projection='polar')\r\n```\r\nThe only thing I don't know how to get is a list of pyplot axes (`pyplot_axes` above). I looked at https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.html and didn't see anything, but perhaps there's another page I'm missing?\n\n### Suggested improvement\n\nAdd a clear description to the changelog (https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot) showing how to write code to reproduce `plt.gca(projection=...)`.\n\n### Matplotlib Version\n\n3.4.2\n\n### Matplotlib documentation version\n\n3.4.2","author":{"url":"https://github.com/dstansby","@type":"Person","name":"dstansby"},"datePublished":"2021-07-30T13:18:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/20770/matplotlib/issues/20770"}
| 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:537cd454-f9a9-fc9e-6e6f-eeefd1a50f7c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB60:33F819:7DA8B8:A8A2CA:6A5307A4 |
| html-safe-nonce | 88bc1cfe916f7142968198fc381cd0c194ff5bc75a281716d8408b6455814835 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjYwOjMzRjgxOTo3REE4Qjg6QThBMkNBOjZBNTMwN0E0IiwidmlzaXRvcl9pZCI6IjM5ODQxMjMyNzAyNzg2MTI5MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4ed601e12c01e2ee5351800a73e41d5a26860ea9dfcade6c6edae2f26c37b025 |
| hovercard-subject-tag | issue:956739213 |
| 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/20770/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1b50e40446d1f397d9134813d5aee3f781789f567432c99b269a7e743c1dfa9/matplotlib/matplotlib/issues/20770 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1b50e40446d1f397d9134813d5aee3f781789f567432c99b269a7e743c1dfa9/matplotlib/matplotlib/issues/20770 |
| og:image:alt | Documentation Link https://matplotlib.org/stable/users/whats_new.html#changes-to-behavior-of-axes-creation-methods-gca-add-axes-add-subplot Problem In version 3.4, passing keyword arguments to plt.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dstansby |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width