Skip to content

MAINT: Updates to formatters in matplotlib.ticker #6253

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

Merged
merged 7 commits into from
Apr 28, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Added support for both x and pos to StrMethodFormatter
This should not break backwards compatibility since extra keywords are allowed
  • Loading branch information
madphysicist committed Apr 11, 2016
commit 9ba1428d7772da82c8c88ee7900f93a6890f3b9b
14 changes: 11 additions & 3 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,22 @@ def __call__(self, x, pos=None):
class StrMethodFormatter(Formatter):
"""
Use a new-style format string (as used by `str.format()`)
to format the tick. The field formatting must be labeled `x`.
to format the tick.

The field used for the value must be labeled `x` and the field used
for the position must be labeled `pos`.
"""
def __init__(self, fmt):
self.fmt = fmt

def __call__(self, x, pos=None):
'Return the format for tick val *x* at position *pos*'
return self.fmt.format(x=x)
"""
Return the formatted label string.

`x` and `pos` are passed to `str.format` as keyword arguments
with those exact names.
"""
return self.fmt.format(x=x, pos=pos)


class OldScalarFormatter(Formatter):
Expand Down