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

Skip to content

Commit 03339b9

Browse files
committed
MNT: remove caching of _tick_space
1 parent 2ec16ee commit 03339b9

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

lib/matplotlib/axis.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ def __init__(self, axes, pickradius=15):
664664
# Initialize here for testing; later add API
665665
self._major_tick_kw = dict()
666666
self._minor_tick_kw = dict()
667-
self._tick_space = None
668667

669668
self.cla()
670669
self._set_scale('linear')
@@ -796,7 +795,6 @@ def set_tick_params(self, which='major', reset=False, **kw):
796795
for tick in self.minorTicks:
797796
tick._apply_params(**self._minor_tick_kw)
798797
self.stale = True
799-
self._tick_space = None
800798

801799
@staticmethod
802800
def _translate_tick_kw(kw, to_init_kw=True):
@@ -1996,16 +1994,14 @@ def set_default_intervals(self):
19961994
self.stale = True
19971995

19981996
def get_tick_space(self):
1999-
if self._tick_space is None:
2000-
ends = self.axes.transAxes.transform([[0, 0], [1, 0]])
2001-
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
2002-
tick = self._get_tick(True)
2003-
# There is a heuristic here that the aspect ratio of tick text
2004-
# is no more than 3:1
2005-
size = tick.label1.get_size() * 3
2006-
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2007-
return np.floor(length / size)
2008-
return self._tick_space
1997+
ends = self.axes.transAxes.transform([[0, 0], [1, 0]])
1998+
length = ((ends[1][0] - ends[0][0]) / self.axes.figure.dpi) * 72.0
1999+
tick = self._get_tick(True)
2000+
# There is a heuristic here that the aspect ratio of tick text
2001+
# is no more than 3:1
2002+
size = tick.label1.get_size() * 3
2003+
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2004+
return np.floor(length / size)
20092005

20102006

20112007
class YAxis(Axis):
@@ -2339,12 +2335,10 @@ def set_default_intervals(self):
23392335
self.stale = True
23402336

23412337
def get_tick_space(self):
2342-
if self._tick_space is None:
2343-
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
2344-
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
2345-
tick = self._get_tick(True)
2346-
# Having a spacing of at least 2 just looks good.
2347-
size = tick.label1.get_size() * 2.0
2348-
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2349-
return np.floor(length / size)
2350-
return self._tick_space
2338+
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
2339+
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
2340+
tick = self._get_tick(True)
2341+
# Having a spacing of at least 2 just looks good.
2342+
size = tick.label1.get_size() * 2.0
2343+
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2344+
return np.floor(length / size)

0 commit comments

Comments
 (0)