Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6353165

Browse files
authored
Merge pull request #16306 from meeseeksmachine/auto-backport-of-pr-16300-on-v3.2.x
Backport PR #16300 on branch v3.2.x (Don't default to negative radii in polar plot.)
2 parents 039fcfe + 47479b0 commit 6353165

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ class RadialLocator(mticker.Locator):
398398
:class:`~matplotlib.ticker.Locator` (which may be different
399399
depending on the scale of the *r*-axis.
400400
"""
401+
401402
def __init__(self, base, axes=None):
402403
self.base = base
403404
self._axes = axes
@@ -429,6 +430,11 @@ def refresh(self):
429430
# docstring inherited
430431
return self.base.refresh()
431432

433+
def nonsingular(self, vmin, vmax):
434+
# docstring inherited
435+
return ((0, 1) if (vmin, vmax) == (-np.inf, np.inf) # Init. limits.
436+
else self.base.nonsingular(vmin, vmax))
437+
432438
def view_limits(self, vmin, vmax):
433439
vmin, vmax = self.base.view_limits(vmin, vmax)
434440
if vmax > vmin:

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,17 @@ def test_log_scales_invalid():
22112211
ax.set_ylim(-1, 10)
22122212

22132213

2214+
def test_polar_no_data():
2215+
plt.subplot(projection="polar")
2216+
ax = plt.gca()
2217+
assert ax.get_rmin() == 0 and ax.get_rmax() == 1
2218+
plt.close("all")
2219+
# Used to behave differently (by triggering an autoscale with no data).
2220+
plt.polar()
2221+
ax = plt.gca()
2222+
assert ax.get_rmin() == 0 and ax.get_rmax() == 1
2223+
2224+
22142225
@image_comparison(['stackplot_test_image', 'stackplot_test_image'])
22152226
def test_stackplot():
22162227
fig = plt.figure()

0 commit comments

Comments
 (0)