Skip to content

Commit 99480b9

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

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-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', None)
821+
if inner_spine is not None:
822+
# Subclasses may not have inner spine.
823+
inner_spine.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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,17 @@ 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+
if self.axis is None:
269+
tr = mtransforms.IdentityTransform()
270+
else:
271+
tr = self.axis.get_transform()
272+
rmin, rmax = tr.transform(self.axes.viewLim.intervaly)
269273
try:
270274
rorigin = self.axes.get_rorigin()
271275
except AttributeError:
272276
rorigin = rmin
277+
else:
278+
rorigin = tr.transform(rorigin)
273279
scaled_diameter = (rmin - rorigin) / (rmax - rorigin)
274280
self._height = scaled_diameter
275281
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')

lib/matplotlib/tests/test_spines.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,15 @@ def test_spines_black_axes():
154154
ax.set_xticks([])
155155
ax.set_yticks([])
156156
ax.set_facecolor((0, 0, 0))
157+
158+
159+
def test_arc_spine_inner_no_axis():
160+
# Backcompat: smoke test that inner arc spine does not need a registered
161+
# axis in order to be drawn
162+
fig = plt.figure()
163+
ax = fig.add_subplot(projection="polar")
164+
inner_spine = ax.spines["inner"]
165+
inner_spine.register_axis(None)
166+
assert ax.spines["inner"].axis is None
167+
168+
fig.draw_without_rendering()

0 commit comments

Comments
 (0)