Backport PR #30223 on branch v3.10.x (Polar log scale: fix inner patch boundary and spine location) by meeseeksmachine · Pull Request #30227 · matplotlib/matplotlib · GitHub
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
8 changes: 7 additions & 1 deletion lib/matplotlib/projections/polar.py
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
Loading