Visitar URL original
DOC: document fmt_xdata and fmt_ydata by tacaswell · Pull Request #25187 · matplotlib/matplotlib · GitHub
The Wayback Machine - https://web.archive.org/web/20230308175226/https://github.com/matplotlib/matplotlib/pull/25187
Skip to content
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

DOC: document fmt_xdata and fmt_ydata #25187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tacaswell
Copy link
Member

PR Summary

Closes #9593

This documents the exact call chain so we can leave the monkey patching route implicit ;)

@tacaswell tacaswell added this to the v3.8.0 milestone Feb 9, 2023

fig, ax = plt.subplots()
ax.set_ylim(-5, 5)
ax.fmt_ydata = lambda v: f'{v:.3g}' if v > 0 else f'({abs(v):.3g})'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ax.fmt_ydata = lambda v: f'{v:.3g}' if v > 0 else f'({abs(v):.3g})'
ax.fmt_ydata = lambda v: f'{v:.3g}' if v >= 0 else f'({abs(v):.3g})'

?

(Not really relevant, but as I happened to see it... And it will consistent with the text below.)

Copy link
Member

Choose a reason for hiding this comment

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

I think perhaps this should not use abs, as it confused me why you didn't just use it directly instead of having the if, since the parentheses weren't initially obvious. But using -v might make it clear that you're doing the if manually on purpose.

@oscargus
Copy link
Contributor

oscargus commented Feb 10, 2023 •

Makes sense to add the same to

# func used to format z -- fall back on major formatters
self.fmt_zdata = None

?

This may just as well go in 3.7? (I guess it would if there was a 3.7-doc? Edit: no, not in 3.7-doc as it also changes the lib-files, but still...)

#:
#: The expected signature is ::
#:
#: def fmt(val: float,/) -> str: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

comma before the slash, ditto below.


fig, ax = plt.subplots()
ax.set_ylim(-5, 5)
ax.fmt_ydata = lambda v: f'{v:.3g}' if v > 0 else f'({abs(v):.3g})'
Copy link
Member

Choose a reason for hiding this comment

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

I think perhaps this should not use abs, as it confused me why you didn't just use it directly instead of having the if, since the parentheses weren't initially obvious. But using -v might make it clear that you're doing the if manually on purpose.

Position Format
---------------

The location of the cursor is show in the UI and generated via the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The location of the cursor is show in the UI and generated via the
The location of the cursor is shown in the UI and generated via the

The location of the cursor is show in the UI and generated via the
`~axes.Axes.format_coord` method which in turn calls the
`~axes.Axes.format_xdata` and `~axes.Axes.format_ydata` methods. The hard
coded format in `~axes.Axes.format_coord` is ``f'x={formtated_x}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
coded format in `~axes.Axes.format_coord` is ``f'x={formtated_x}
coded format in `~axes.Axes.format_coord` is ``f'x={formatted_x}

@ksunden
Copy link
Member

ksunden commented Mar 3, 2023

Do we want to get this in prior 3.7.1, which we are looking to tag today?

@QuLogic QuLogic modified the milestones: v3.7.1, v3.7.2 Mar 4, 2023
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.

DOC: need discoverable documentation for Axes.fmt_xdata
6 participants