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

Skip to content

Commit 94f04a9

Browse files
committed
Make pickles work again.
1 parent 775db02 commit 94f04a9

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/matplotlib/axis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,11 @@ def set_pickradius(self, pickradius):
15991599
"""
16001600
self.pickradius = pickradius
16011601

1602+
# Helper for set_ticklabels. Defining it here makes it pickleable.
1603+
@staticmethod
1604+
def _format_with_dict(x, pos, tickd):
1605+
return tickd.get(x, "")
1606+
16021607
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
16031608
r"""
16041609
Set the text values of the tick labels.
@@ -1630,7 +1635,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
16301635
else self.get_major_locator())
16311636
if isinstance(locator, mticker.FixedLocator):
16321637
tickd = {loc: lab for loc, lab in zip(locator.locs, ticklabels)}
1633-
formatter = mticker.FuncFormatter(lambda x, pos: tickd.get(x, ""))
1638+
formatter = mticker.FuncFormatter(self._format_with_dict, tickd)
16341639
else:
16351640
formatter = mticker.FixedFormatter(ticklabels)
16361641
if minor:

lib/matplotlib/ticker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,13 @@ 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.
382+
tick label. The function may take additional arguments that are
383+
supplied upon instantiation.
383384
"""
384385

385-
def __init__(self, func):
386+
def __init__(self, func, *args):
386387
self.func = func
388+
self.args = args
387389
self.offset_string = ""
388390

389391
def __call__(self, x, pos=None):
@@ -392,7 +394,7 @@ def __call__(self, x, pos=None):
392394
393395
*x* and *pos* are passed through as-is.
394396
"""
395-
return self.func(x, pos)
397+
return self.func(x, pos, *self.args)
396398

397399
def get_offset(self):
398400
return self.offset_string

0 commit comments

Comments
 (0)