Skip to content

Commit 41b50c0

Browse files
committed
Fix polar inner patch boundary and spine location for log scale
1 parent 58b6a06 commit 41b50c0

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ def _init_axis(self):
817817
self.xaxis = ThetaAxis(self, clear=False)
818818
self.yaxis = RadialAxis(self, clear=False)
819819
self.spines['polar'].register_axis(self.yaxis)
820+
inner_spine = self.spines.get('inner')
821+
if inner_spine is not None:
822+
# Subclasses may not have inner spine.
823+
self.spines['inner'].register_axis(self.yaxis)
820824

821825
def _set_lim_and_transforms(self):
822826
# A view limit where the minimum radius can be locked if the user
@@ -961,7 +965,9 @@ def draw(self, renderer):
961965
thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
962966
if thetamin > thetamax:
963967
thetamin, thetamax = thetamax, thetamin
964-
rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
968+
rscale_tr = self.yaxis.get_transform()
969+
rmin, rmax = ((rscale_tr.transform(self._realViewLim.intervaly) -
970+
rscale_tr.transform(self.get_rorigin())) *
965971
self.get_rsign())
966972
if isinstance(self.patch, mpatches.Wedge):
967973
# Backwards-compatibility: Any subclassed Axes might override the

lib/matplotlib/spines.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,14 @@ def _adjust_location(self):
265265
self._path = mpath.Path.arc(np.rad2deg(low), np.rad2deg(high))
266266

267267
if self.spine_type == 'bottom':
268-
rmin, rmax = self.axes.viewLim.intervaly
268+
tr = self.axis.get_transform()
269+
rmin, rmax = tr.transform(self.axes.viewLim.intervaly)
269270
try:
270271
rorigin = self.axes.get_rorigin()
271272
except AttributeError:
272273
rorigin = rmin
274+
else:
275+
rorigin = tr.transform(rorigin)
273276
scaled_diameter = (rmin - rorigin) / (rmax - rorigin)
274277
self._height = scaled_diameter
275278
self._width = scaled_diameter

lib/matplotlib/tests/test_polar.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,26 @@ def test_polar_log():
482482
ax.plot(np.linspace(0, 2 * np.pi, n), np.logspace(0, 2, n))
483483

484484

485+
@check_figures_equal()
486+
def test_polar_log_rorigin(fig_ref, fig_test):
487+
# Test that equivalent linear and log radial settings give the same axes patch
488+
# and spines.
489+
ax_ref = fig_ref.add_subplot(projection='polar', facecolor='red')
490+
ax_ref.set_rlim(0, 2)
491+
ax_ref.set_rorigin(-3)
492+
ax_ref.set_rticks(np.linspace(0, 2, 5))
493+
494+
ax_test = fig_test.add_subplot(projection='polar', facecolor='red')
495+
ax_test.set_rscale('log')
496+
ax_test.set_rlim(1, 100)
497+
ax_test.set_rorigin(10**-3)
498+
ax_test.set_rticks(np.logspace(0, 2, 5))
499+
500+
for ax in ax_ref, ax_test:
501+
# Radial tick labels should be the only difference, so turn them off.
502+
ax.tick_params(labelleft=False)
503+
504+
485505
def test_polar_neg_theta_lims():
486506
fig = plt.figure()
487507
ax = fig.add_subplot(projection='polar')

0 commit comments

Comments
 (0)