diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 2aa1bd35e70f..9da973c976e6 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -385,6 +385,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 @@ -416,6 +417,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 765277949ac8..cddddbc0909a 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2240,6 +2240,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()