Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f51d58c

Browse files
committed
ENH: Added support for both x and pos to StrMethodFormatter
This should not break backwards compatibility since extra keywords are allowed
1 parent 5da6870 commit f51d58c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/matplotlib/ticker.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,22 @@ def __call__(self, x, pos=None):
363363
class StrMethodFormatter(Formatter):
364364
"""
365365
Use a new-style format string (as used by `str.format()`)
366-
to format the tick. The field formatting must be labeled `x`.
366+
to format the tick.
367+
368+
The field used for the value must be labeled `x` and the field used
369+
for the position must be labeled `pos`.
367370
"""
368371
def __init__(self, fmt):
369372
self.fmt = fmt
370373

371374
def __call__(self, x, pos=None):
372-
'Return the format for tick val *x* at position *pos*'
373-
return self.fmt.format(x=x)
375+
"""
376+
Return the formatted label string.
377+
378+
`x` and `pos` are passed to `str.format` as keyword arguments
379+
with those exact names.
380+
"""
381+
return self.fmt.format(x=x, pos=pos)
374382

375383

376384
class OldScalarFormatter(Formatter):

0 commit comments

Comments
 (0)