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

Skip to content

Commit 6bfbb6c

Browse files
committed
Use partial in set_ticklabels instead of an argument in FuncFormatter.
1 parent 94f04a9 commit 6bfbb6c

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import datetime
6+
import functools
67
import logging
78

89
import numpy as np
@@ -1601,7 +1602,7 @@ def set_pickradius(self, pickradius):
16011602

16021603
# Helper for set_ticklabels. Defining it here makes it pickleable.
16031604
@staticmethod
1604-
def _format_with_dict(x, pos, tickd):
1605+
def _format_with_dict(tickd, x, pos):
16051606
return tickd.get(x, "")
16061607

16071608
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
@@ -1635,7 +1636,8 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
16351636
else self.get_major_locator())
16361637
if isinstance(locator, mticker.FixedLocator):
16371638
tickd = {loc: lab for loc, lab in zip(locator.locs, ticklabels)}
1638-
formatter = mticker.FuncFormatter(self._format_with_dict, tickd)
1639+
func = functools.partial(self._format_with_dict, tickd)
1640+
formatter = mticker.FuncFormatter(func)
16391641
else:
16401642
formatter = mticker.FixedFormatter(ticklabels)
16411643
if minor:

lib/matplotlib/ticker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,11 @@ class FuncFormatter(Formatter):
379379
380380
The function should take in two inputs (a tick value ``x`` and a
381381
position ``pos``), and return a string containing the corresponding
382-
tick label. The function may take additional arguments that are
383-
supplied upon instantiation.
382+
tick label.
384383
"""
385384

386-
def __init__(self, func, *args):
385+
def __init__(self, func):
387386
self.func = func
388-
self.args = args
389387
self.offset_string = ""
390388

391389
def __call__(self, x, pos=None):
@@ -394,7 +392,7 @@ def __call__(self, x, pos=None):
394392
395393
*x* and *pos* are passed through as-is.
396394
"""
397-
return self.func(x, pos, *self.args)
395+
return self.func(x, pos)
398396

399397
def get_offset(self):
400398
return self.offset_string

0 commit comments

Comments
 (0)