Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,25 @@ def __call__(self):
return [tick for tick in self.base() if tick > rorigin]
return self.base()

def _zero_in_bounds(self):
"""
Return True if zero is within the valid values for the
scale of the radial axis.
"""
vmin, vmax = self._axes.yaxis._scale.limit_range_for_scale(0, 1, 1e-5)
return vmin == 0

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))
if self._zero_in_bounds() and (vmin, vmax) == (-np.inf, np.inf):
# Initial view limits
return (0, 1)
else:
return self.base.nonsingular(vmin, vmax)

def view_limits(self, vmin, vmax):
vmin, vmax = self.base.view_limits(vmin, vmax)
if vmax > vmin:
if self._zero_in_bounds() and vmax > vmin:
# this allows inverted r/y-lims
vmin = min(0, vmin)
return mtransforms.nonsingular(vmin, vmax)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ def test_polar_no_data():
assert ax.get_rmin() == 0 and ax.get_rmax() == 1


def test_polar_default_log_lims():
plt.subplot(projection='polar')
ax = plt.gca()
ax.set_rscale('log')
assert ax.get_rmin() > 0


def test_polar_not_datalim_adjustable():
ax = plt.figure().add_subplot(projection="polar")
with pytest.raises(ValueError):
Expand Down