Skip to content

Improve MaxNLocator, AutoLocator signatures.#31788

Open
anntzer wants to merge 1 commit into
matplotlib:mainfrom
anntzer:locsig
Open

Improve MaxNLocator, AutoLocator signatures.#31788
anntzer wants to merge 1 commit into
matplotlib:mainfrom
anntzer:locsig

Conversation

@anntzer

@anntzer anntzer commented May 30, 2026

Copy link
Copy Markdown
Contributor

Directly set the defaults of MaxNLocator in the constructor signature (with a cutout for nbins=None), rather than in a separate variable.

Support passing kwargs to AutoLocator as well (they're already supported by MaxNLocator).

PR summary

AI Disclosure

PR checklist

@anntzer anntzer force-pushed the locsig branch 3 times, most recently from cc2ccf3 to ab3e78b Compare May 30, 2026 19:12
Comment thread lib/matplotlib/ticker.py
min_n_ticks=2)

def __init__(self, nbins=None, **kwargs):
default_params = _api.deprecated("3.12")(property(lambda self: dict(

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.

Technically, this is breaking because it removes write access, i.e. replacing the whole dict, without prior warning.

But I think I'm ok with that. It should be very rare. https://github.com/search?q=%2FMaxNLocator%5C.default_params%2F+language%3APython+NOT+is%3Afork&type=code does not yield any such cases. If people overwrite defaults, they tend to do it on a per-element basis.

@timhoffm timhoffm added this to the v3.12.0 milestone May 31, 2026
Comment thread lib/matplotlib/ticker.py
Comment thread lib/matplotlib/ticker.py Outdated
kwargs['nbins'] = nbins
self.set_params(**{**self.default_params, **kwargs})
self.set_params(
nbins=nbins if nbins is not None else 10,

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.

Do we need the check for None here? The parameter is documented as only taking an integer or "auto", and it already defaults to 10.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I think we don't need to. Fixed.

Directly set the defaults of MaxNLocator in the constructor signature
(with a cutout for `nbins=None`), rather than in a separate variable.

Support passing kwargs to AutoLocator as well (they're already supported
by MaxNLocator).
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.

3 participants