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
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented May 30, 2026

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 2 times, most recently from 201ae87 to cc2ccf3 Compare May 30, 2026 13:22
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).
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 on lines +2130 to +2135
nbins=10,
steps=None,
integer=False,
symmetric=False,
prune=None,
min_n_ticks=2,
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.

Is it worth making these keyword-only, in case we want to re-order them or insert another parameter in future?

Comment thread lib/matplotlib/ticker.py
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.

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