From 47479b04b6718a65ebaac094db106d44b40da509 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 23 Jan 2020 09:22:38 -0800 Subject: [PATCH] Backport PR #16300: Don't default to negative radii in polar plot. --- lib/matplotlib/projections/polar.py | 6 ++++++ lib/matplotlib/tests/test_axes.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index c33fa0560f0b..61f2e5a6a539 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -398,6 +398,7 @@ class RadialLocator(mticker.Locator): :class:`~matplotlib.ticker.Locator` (which may be different depending on the scale of the *r*-axis. """ + def __init__(self, base, axes=None): self.base = base self._axes = axes @@ -429,6 +430,11 @@ def refresh(self): # docstring inherited return self.base.refresh() + def nonsingular(self, vmin, vmax): + # docstring inherited + return ((0, 1) if (vmin, vmax) == (-np.inf, np.inf) # Init. limits. + else self.base.nonsingular(vmin, vmax)) + def view_limits(self, vmin, vmax): vmin, vmax = self.base.view_limits(vmin, vmax) if vmax > vmin: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 250a0db047ca..290dfa64664b 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2211,6 +2211,17 @@ def test_log_scales_invalid(): ax.set_ylim(-1, 10) +def test_polar_no_data(): + plt.subplot(projection="polar") + ax = plt.gca() + assert ax.get_rmin() == 0 and ax.get_rmax() == 1 + plt.close("all") + # Used to behave differently (by triggering an autoscale with no data). + plt.polar() + ax = plt.gca() + assert ax.get_rmin() == 0 and ax.get_rmax() == 1 + + @image_comparison(['stackplot_test_image', 'stackplot_test_image']) def test_stackplot(): fig = plt.figure()