8000 Merge pull request #24763 from dstansby/polar-nonsingular · matplotlib/matplotlib@fc5d316 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc5d316

Browse files
authored
Merge pull request #24763 from dstansby/polar-nonsingular
Allow polar scales where zero is not in valid interval
2 parents 88e43f3 + 4507ae5 commit fc5d316

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,25 @@ def __call__(self):
422422
return [tick for tick in self.base() if tick > rorigin]
423423
return self.base()
424424

425+
def _zero_in_bounds(self):
426+
"""
427+
Return True if zero is within the valid values for the
428+
scale of the radial axis.
429+
"""
430+
vmin, vmax = self._axes.yaxis._scale.limit_range_for_scale(0, 1, 1e-5)
431+
return vmin == 0
432+
425433
def nonsingular(self, vmin, vmax):
426434
# docstring inherited
427-
return ((0, 1) if (vmin, vmax) == (-np.inf, np.inf) # Init. limits.
428-
else self.base.nonsingular(vmin, vmax))
435+
if self._zero_in_bounds() and (vmin, vmax) == (-np.inf, np.inf):
436+
# Initial view limits
437+
return (0, 1)
438+
else:
439+
return self.base.nonsingular(vmin, vmax)
429440

430441
def view_limits(self, vmin, vmax):
431442
vmin, vmax = self.base.view_limits(vmin, vmax)
432-
if vmax > vmin:
443+
if self._zero_in_bounds() and vmax > vmin:
433444
# this allows inverted r/y-lims
434445
vmin = min(0, vmin)
435446
return mtransforms.nonsingular(vmin, vmax)

lib/matplotlib/tests/test_polar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ def test_polar_no_data():
291291
assert ax.get_rmin() == 0 and ax.get_rmax() == 1
292292

293293

294+
def test_polar_default_log_lims():
295+
plt.subplot(projection='polar')
296+
ax = plt.gca()
297+
ax.set_rscale('log')
298+
assert ax.get_rmin() > 0
299+
300+
294301
def test_polar_not_datalim_adjustable():
295302
ax = plt.figure().add_subplot(projection="polar")
296303
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)
0