Skip to content

Backport PR #30223 on branch v3.10.x (Polar log scale: fix inner patch boundary and spine location) #30227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
8 changes: 7 additions & 1 deletion lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@ def _init_axis(self):
self.xaxis = ThetaAxis(self, clear=False)
self.yaxis = RadialAxis(self, clear=False)
self.spines['polar'].register_axis(self.yaxis)
inner_spine = self.spines.get('inner', None)
if inner_spine is not None:
# Subclasses may not have inner spine.
inner_spine.register_axis(self.yaxis)

def _set_lim_and_transforms(self):
# A view limit where the minimum radius can be locked if the user
Expand Down Expand Up @@ -1002,7 +1006,9 @@ def draw(self, renderer):
thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
if thetamin > thetamax:
thetamin, thetamax = thetamax, thetamin
rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
rscale_tr = self.yaxis.get_transform()
rmin, rmax = ((rscale_tr.transform(self._realViewLim.intervaly) -
rscale_tr.transform(self.get_rorigin())) *
self.get_rsign())
if isinstance(self.patch, mpatches.Wedge):
# Backwards-compatibility: Any subclassed Axes might override the
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,17 @@ def _adjust_location(self):
self._path = mpath.Path.arc(np.rad2deg(low), np.rad2deg(high))

if self.spine_type == 'bottom':
rmin, rmax = self.axes.viewLim.intervaly
if self.axis is None:
tr = mtransforms.IdentityTransform()
else:
tr = self.axis.get_transform()
rmin, rmax = tr.transform(self.axes.viewLim.intervaly)
try:
rorigin = self.axes.get_rorigin()
except AttributeError:
rorigin = rmin
else:
rorigin = tr.transform(rorigin)
scaled_diameter = (rmin - rorigin) / (rmax - rorigin)
self._height = scaled_diameter
self._width = scaled_diameter
Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,26 @@ def test_polar_log():
ax.plot(np.linspace(0, 2 * np.pi, n), np.logspace(0, 2, n))


@check_figures_equal()
def test_polar_log_rorigin(fig_ref, fig_test):
# Test that equivalent linear and log radial settings give the same axes patch
# and spines.
ax_ref = fig_ref.add_subplot(projection='polar', facecolor='red')
ax_ref.set_rlim(0, 2)
ax_ref.set_rorigin(-3)
ax_ref.set_rticks(np.linspace(0, 2, 5))

ax_test = fig_test.add_subplot(projection='polar', facecolor='red')
ax_test.set_rscale('log')
ax_test.set_rlim(1, 100)
ax_test.set_rorigin(10**-3)
ax_test.set_rticks(np.logspace(0, 2, 5))

for ax in ax_ref, ax_test:
# Radial tick labels should be the only difference, so turn them off.
ax.tick_params(labelleft=False)


def test_polar_neg_theta_lims():
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ def test_spines_black_axes():
ax.set_xticks([])
ax.set_yticks([])
ax.set_facecolor((0, 0, 0))


def test_arc_spine_inner_no_axis():
# Backcompat: smoke test that inner arc spine does not need a registered
# axis in order to be drawn
fig = plt.figure()
ax = fig.add_subplot(projection="polar")
inner_spine = ax.spines["inner"]
inner_spine.register_axis(None)
assert ax.spines["inner"].axis is None

fig.draw_without_rendering()
Loading