Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix: Inner circle rendering with log-scale + rorigin in polar plots (Fixes #30179) #30185

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 13 additions & 7 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,15 +1175,21 @@
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)

Check warning on line 1189 in lib/matplotlib/projections/polar.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/projections/polar.py#L1188-L1189

Added lines #L1188 - L1189 were not covered by tests
return self


def get_rorigin(self):
"""
Returns
Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np
import matplotlib.pyplot as plt

Check failure on line 2 in lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 `matplotlib.pyplot` imported but unused Raw Output: message:"`matplotlib.pyplot` imported but unused" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py" range:{start:{line:2 column:29} end:{line:2 column:32}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F401" url:"https://docs.astral.sh/ruff/rules/unused-import"} suggestions:{range:{start:{line:2 column:1} end:{line:3 column:1}}}
from matplotlib.testing.decorators import check_figures_equal

@check_figures_equal()

Check failure on line 5 in lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py" range:{start:{line:5 column:1} end:{line:5 column:2}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:4 column:1} end:{line:5 column:1}} text:"\n\n"}
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)

Check warning on line 14 in lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py#L14

Added line #L14 was not covered by tests

# 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)

Check warning on line 20 in lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_axes/test_polar_log_rorigin.py#L17-L20

Added lines #L17 - L20 were not covered by tests
Loading