diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 948b3a6e704f..052915ab2cf0 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -1175,15 +1175,21 @@ def get_rmin(self): return self.viewLim.ymin def set_rorigin(self, rorigin): - """ - Update the radial origin. - - Parameters - ---------- - rorigin : float - """ self._originViewLim.locked_y0 = rorigin + # Fix: Adjust tick/grid when using log scale + self._rorigin = rorigin # store internally for use elsewhere + if hasattr(self, 'yaxis'): + if self.yaxis.get_scale() == 'log': + locator = self.yaxis.get_major_locator() + if locator is not None: + locs = locator.tick_values(self.get_rmin(), self.get_rmax()) + # Offset tick locations based on origin, only if loc > 0 (log scale) + adjusted_locs = [abs(rorigin) + loc for loc in locs if loc > 0] + self.yaxis.set_ticks(adjusted_locs) + return self + + def get_rorigin(self): """ Returns diff --git a/lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py b/lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py new file mode 100644 index 000000000000..fb55fdeb5c3f --- /dev/null +++ b/lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py @@ -0,0 +1,20 @@ +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.testing.decorators import check_figures_equal + +@check_figures_equal() +def test_polar_log_rorigin_rendering(fig_test, fig_ref): + r = np.logspace(-1, 1, 500) + theta = np.linspace(0, 2 * np.pi, 500) + + # Reference (correct rendering after fix) + ax_ref = fig_ref.add_subplot(1, 1, 1, projection='polar') + ax_ref.set_rscale('log') + ax_ref.set_rorigin(-0.5) + ax_ref.plot(theta, r) + + # Test output (same code, expected to match) + ax_test = fig_test.add_subplot(1, 1, 1, projection='polar') + ax_test.set_rscale('log') + ax_test.set_rorigin(-0.5) + ax_test.plot(theta, r)