Skip to content

FIX: Polar Radial Tick Warnings Labels Bug#31577

Merged
rcomer merged 9 commits into
matplotlib:mainfrom
beelauuu:fix-polar-radial-ticklabels-warning
Apr 29, 2026
Merged

FIX: Polar Radial Tick Warnings Labels Bug#31577
rcomer merged 9 commits into
matplotlib:mainfrom
beelauuu:fix-polar-radial-ticklabels-warning

Conversation

@beelauuu

@beelauuu beelauuu commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

PR summary

Closes #31574

Minimal fix (for now) for set_ticks(ticks, labels) or set_ticklabels(labels) on a polar axes emitting a spurious UserWarning:

"set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator."

The fix extends both the set_ticklabels and _set_formatter guards to also match locators that wrap a FixedLocator via a .base attribute, using duck-typing to avoid importing RadialLocator into axis.py.

AI Disclosure

Claude helped identify the root cause, write the regression test, and diagnose some pre-commit hook configuration issues I was having (python_version / target-version missing from pyproject.toml).

PR checklist

…bels

Extend the FixedLocator isinstance check in Axis.set_ticklabels and
_set_formatter to also recognise locators that wrap a FixedLocator via
a .base attribute (e.g. RadialLocator used by polar axes).  Previously
calling set_ticks(ticks, labels) or set_ticklabels(labels) on a polar
axis would always hit the else branch and emit a spurious warning
because RadialAxis.set_major_locator automatically wraps any locator in
a RadialLocator, hiding the inner FixedLocator from the isinstance check.

Add a regression test covering both the combined set_ticks path and the
separate set_rticks / set_ticklabels path, and asserting that a label
count mismatch still raises ValueError.

Also add python_version = "3.11" to [tool.mypy] and target-version =
"py311" to [tool.ruff] in pyproject.toml to match the project's minimum
supported Python version, and update .pyi stub imports accordingly.
@beelauuu

Copy link
Copy Markdown
Contributor Author

Not sure if the code coverage issue is a blocker, let me know.

@rcomer rcomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @beelauuu. Codecov is currently for information only and I'm happy that the actual change is covered, so no problem there.

Comment thread lib/matplotlib/tests/test_polar.py Outdated
Comment thread lib/matplotlib/tests/test_polar.py Outdated
Comment thread lib/matplotlib/tests/test_polar.py Outdated
Comment thread lib/matplotlib/tests/test_polar.py Outdated
beelauuu and others added 2 commits April 28, 2026 21:46
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Comment thread lib/matplotlib/tests/test_polar.py Outdated
# the "set_ticklabels() should only be used with a fixed number of ticks"
# UserWarning when set_ticks()/set_rticks() was called first.

# Path 1: set_rticks then set_ticklabels separately

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Path 1: set_rticks then set_ticklabels separately

@timhoffm timhoffm added this to the v3.11.0 milestone Apr 29, 2026
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@rcomer rcomer merged commit 9127a70 into matplotlib:main Apr 29, 2026
41 checks passed
rcomer added a commit that referenced this pull request Apr 29, 2026
Co-authored-by: Brian Lau <103338659+beelauuu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: polar projection with labels on set_ticks gives UserWarning

3 participants