Skip to content

Commit 9933e23

Browse files
authored
Merge pull request #16300 from anntzer/default-rlims
Don't default to negative radii in polar plot.
2 parents 7e1a47c + 670d561 commit 9933e23

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/projections/polar.py

+6
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ class RadialLocator(mticker.Locator):
385385
:class:`~matplotlib.ticker.Locator` (which may be different
386386
depending on the scale of the *r*-axis.
387387
"""
388+
388389
def __init__(self, base, axes=None):
389390
self.base = base
390391
self._axes = axes
@@ -416,6 +417,11 @@ def refresh(self):
416417
# docstring inherited
417418
return self.base.refresh()
418419

420+
def nonsingular(self, vmin, vmax):
421+
# docstring inherited
422+
return ((0, 1) if (vmin, vmax) == (-np.inf, np.inf) # Init. limits.
423+
else self.base.nonsingular(vmin, vmax))
424+
419425
def view_limits(self, vmin, vmax):
420426
vmin, vmax = self.base.view_limits(vmin, vmax)
421427
if vmax > vmin:

lib/matplotlib/tests/test_axes.py

+11
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,17 @@ def test_log_scales_invalid():
22402240
ax.set_ylim(-1, 10)
22412241

22422242

2243+
def test_polar_no_data():
2244+
plt.subplot(projection="polar")
2245+
ax = plt.gca()
2246+
assert ax.get_rmin() == 0 and ax.get_rmax() == 1
2247+
plt.close("all")
2248+
# Used to behave differently (by triggering an autoscale with no data).
2249+
plt.polar()
2250+
ax = plt.gca()
2251+
assert ax.get_rmin() == 0 and ax.get_rmax() == 1
2252+
2253+
22432254
@image_comparison(['stackplot_test_image', 'stackplot_test_image'])
22442255
def test_stackplot():
22452256
fig = plt.figure()

0 commit comments

Comments
 (0)