Skip to content

Commit daf4c05

Browse files
Backport PR matplotlib#30223: Polar log scale: fix inner patch boundary and spine location (matplotlib#30227)
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent 22b8286 commit daf4c05

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
@@ -857,6 +857,10 @@ def _init_axis(self):
857857
self.xaxis = ThetaAxis(self, clear=False)
858858
self.yaxis = RadialAxis(self, clear=False)
859859
self.spines['polar'].register_axis(self.yaxis)
860+
inner_spine = self.spines.get('inner', None)
861+
if inner_spine is not None:
862+
# Subclasses may not have inner spine.
863+
inner_spine.register_axis(self.yaxis)
860864

861865
def _set_lim_and_transforms(self):
862866
# A view limit where the minimum radius can be locked if the user
@@ -1002,7 +1006,9 @@ def draw(self, renderer):
10021006
thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
10031007
if thetamin > thetamax:
10041008
thetamin, thetamax = thetamax, thetamin
1005-
rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
1009+
rscale_tr = self.yaxis.get_transform()
1010+
rmin, rmax = ((rscale_tr.transform(self._realViewLim.intervaly) -
1011+
rscale_tr.transform(self.get_rorigin())) *
10061012
self.get_rsign())
10071013
if isinstance(self.patch, mpatches.Wedge):
10081014
# 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)