Skip to content

Tweak Formatter method docstrings.#31392

Merged
timhoffm merged 1 commit intomatplotlib:mainfrom
anntzer:df
Mar 26, 2026
Merged

Tweak Formatter method docstrings.#31392
timhoffm merged 1 commit intomatplotlib:mainfrom
anntzer:df

Conversation

@anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 26, 2026

In particular, make it explicit which methods are used for what purpose.

PR summary

AI Disclosure

PR checklist

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Some clarification comments.


Semi-OT: Should we constrain the public API?

In particular, I don't think set_locs is needed publically. Calling format_ticks(values) should be sufficent and it should be possible to make the locs state an implementation detail.

Additionally, one could check / clarify the relation of __call__ and format_data. Are both needed publically?

Comment on lines +232 to +236
Return a short string version of a value (defaulting to
`.Formatter.format_data`), to be used for the mouseover text.
Defaults to the position-independent long value.
The mouseover text can be customized by setting the ``Axes.fmt_xdata``
and ``Axes.fmt_ydata`` attributes.
Copy link
Member

@timhoffm timhoffm Mar 26, 2026

Choose a reason for hiding this comment

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

Suggested change
Return a short string version of a value (defaulting to
`.Formatter.format_data`), to be used for the mouseover text.
Defaults to the position-independent long value.
The mouseover text can be customized by setting the ``Axes.fmt_xdata``
and ``Axes.fmt_ydata`` attributes.
Return a short string version of *value*, used for the mouseover text.
This defaults to the long version `.Formatter.format_data`, but
subclasses may override this.
Note: The user can override the mouseover text by setting the
``Axes.fmt_xdata`` and ``Axes.fmt_ydata`` attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went for a slightly different version where I drop the mention of "long" and "short" (in fact format_data_short can easily be longer than format_data).

Comment on lines +216 to +218
Return the tick labels for all the ticks at once.
This method is used to generate tick labels.
Copy link
Member

@timhoffm timhoffm Mar 26, 2026

Choose a reason for hiding this comment

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

Suggested change
Return the tick labels for all the ticks at once.
This method is used to generate tick labels.
Return the tick labels strings for all *values*.
This method is the public API to generate a meaningful format
for a set of values, e.g. ensures an appropriate precision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 26, 2026

The formatter API is a bit all over the place and I had tried a long time ago to rework it in #5804, but that went nowhere. Here I'm just trying to document the status quo.
Currently format_data is actually an implementation detail, and only format_ticks (which delegates to __call__) is actually used. But format_data_short is used (for mouseovering).

In particular, make it explicit which methods are used for what purpose.
@timhoffm timhoffm added this to the v3.11.0 milestone Mar 26, 2026
@timhoffm timhoffm merged commit ff47144 into matplotlib:main Mar 26, 2026
24 of 40 checks passed
@timhoffm
Copy link
Member

I've created #31396 as a tracking issue for possible future formatter API changes.

@anntzer anntzer deleted the df branch March 26, 2026 17:43
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.

2 participants