Skip to content

[Bug]: Second and subsequent calls to plt.polar() return an Axis object and do not plot #21113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
beckja opened this issue Sep 18, 2021 · 6 comments
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Milestone

Comments

@beckja
Copy link
Contributor

beckja commented Sep 18, 2021

Bug summary

When plt.polar() is called while the current axes are a PolarAxes object, the call just returns the axes again without plotting the new data.

The code for polar() in pyplot.py is easily fixed by changing "return ax" to "return ax.plot(*args, **kwargs)".

Code for reproduction

import matplotlib.pyplot as plt

h1 = plt.polar([0],[1],'ro')

h2 = plt.polar([1.57],[.5], 'bo')

plt.show()

Actual outcome

Only the first point is plotted. Note that h1 is a list of length 1 of Line2D objects, while h2 is a PolarAxesSubplot object.

Expected outcome

Both points should be plotted. Both h1 and h2 should be lists of length 1 of Line2D objects.

Operating system

Windows

Matplotlib Version

3.4.3

Matplotlib Backend

No response

Python version

3.9

Jupyter version

No response

Other libraries

No response

Installation

conda

Conda channel

No response

@beckja
Copy link
Contributor Author

beckja commented Sep 18, 2021

Suggested slightly cleaner version:

def polar(*args, **kwargs):
"""
Make a polar plot.

call signature::

  polar(theta, r, **kwargs)

Multiple *theta*, *r* arguments are supported, with format strings, as in
`plot`.
"""
# If an axis already exists, check if it has a polar projection
if gcf().get_axes():
    ax = gca()
    if not isinstance(ax, PolarAxes):
        _api.warn_external('Trying to create polar plot on an Axes '
                           'that does not have a polar projection.')
else:
    ax = axes(projection="polar")
return ax.plot(*args, **kwargs)

@timhoffm
Copy link
Member

Yes. Do you want to make a pull request?

@timhoffm
Copy link
Member

Note: This is a regression from #19153 introduced into 3.4.0.

@anntzer anntzer added this to the v3.4.4 milestone Sep 19, 2021
@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Sep 19, 2021
@beckja
Copy link
Contributor Author

beckja commented Sep 19, 2021

I'm working the pull request and will submit shortly.

@tacaswell
Copy link
Member

Thank you @beckja !

@QuLogic
Copy link
Member

QuLogic commented Sep 20, 2021

Closed by #21131.

@QuLogic QuLogic closed this as completed Sep 20, 2021
@QuLogic QuLogic modified the milestones: v3.4.4, v3.5.0 Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants