X Tutup
Skip to content

DOC: Show off FuncFormatter as a decorator#8396

Merged
NelleV merged 2 commits intomatplotlib:masterfrom
phobson:doc-func-formatter-as-dec
Mar 29, 2017
Merged

DOC: Show off FuncFormatter as a decorator#8396
NelleV merged 2 commits intomatplotlib:masterfrom
phobson:doc-func-formatter-as-dec

Conversation

@phobson
Copy link
Copy Markdown
Member

@phobson phobson commented Mar 28, 2017

Just a minor update to an example that shows how to use ticker.FuncFormatter as a decorator.

Also modified example to use the figure object instead of the state machine.

Copy link
Copy Markdown
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

LGTM

@NelleV NelleV merged commit 7a0ed13 into matplotlib:master Mar 29, 2017
@phobson phobson deleted the doc-func-formatter-as-dec branch March 29, 2017 14:27
ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))
ax.xaxis.set_major_formatter(ticker.FuncFormatter(major_formatter))
ax.xaxis.set_major_formatter(major_formatter)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missed the PR, but I think if you really want to suggest using decorator syntax, you can do even better with

@ax.xaxis.set_major_formatter
@ticker.FuncFormatter
def _(x, pos):
    return ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's pretty cool, but I think it's a little too clever for the examples/gallery.

My main goal to show how to explicitly act on the Axes/Axis objects and avoid nested function calls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's fair.
As a side note this file should be renamed tick_formatters.py consistently with other examples which have importable names.

@QuLogic QuLogic added this to the v2.1 milestone Aug 12, 2021
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.

4 participants

X Tutup