Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Doc]: How to replicate behaviour of plt.gca(projection=...)? #20770

Copy link
Copy link
Closed
@dstansby

Description

@dstansby
Issue body actions

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 using plt.gca(projection='polar') to:

  1. Check if a polar projection axes exists, and if so return it
  2. If not, create a new axes with a polar projection

Looking 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:

if len(pyplot_axes):
    if plt.gca().name != 'polar':
        raise RuntimeError('Axes isn't polar projection')
    else:
        return plt.gca()
else:
    return plt.subplot(projection='polar')

The 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?

Suggested improvement

Add 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=...).

Matplotlib Version

3.4.2

Matplotlib documentation version

3.4.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.