10000 MNT: Deprecate plt.polar() with an existing non-polar Axes by timhoffm · Pull Request #28946 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

MNT: Deprecate plt.polar() with an existing non-polar Axes #28946

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

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations/28946-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Calling ``pyplot.polar()`` with an existing non-polar Axes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This currently plots the data into the non-polar Axes, ignoring
the "polar" intention. This usage scenario is deprecated and
will raise an error in the future.
27 changes: 21 additions & 6 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,17 +2686,32 @@ def polar(*args, **kwargs) -> list[Line2D]:

call signature::

polar(theta, r, **kwargs)

Multiple *theta*, *r* arguments are supported, with format strings, as in
`plot`.
polar(theta, r, [fmt], **kwargs)

This is a convenience wrapper around `.pyplot.plot`. It ensures that the
current Axes is polar (or creates one if needed) and then passes all parameters
to ``.pyplot.plot``.

.. note::
When making polar plots using the :ref:`pyplot API <pyplot_interface>`,
``polar()`` should typically be the first command because that makes sure
a polar Axes is created. Using other commands such as ``plt.title()``
before this can lead to the implicit creation of a rectangular Axes, in which
case a subsequent ``polar()`` call will fail.
"""
# 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.')
_api.warn_deprecated(
"3.10",
message="There exists a non-polar current Axes. Therefore, the "
"resulting plot from 'polar()' is non-polar. You likely "
"should call 'polar()' before any other pyplot plotting "
"commands. "
"Support for this scenario is deprecated in %(since)s and "
"will raise an error in %(removal)s"
)
else:
ax = axes(projection="polar")
return ax.plot(*args, **kwargs)
Expand Down
Loading
0