8000 Cache tick space calculation · matplotlib/matplotlib@63c9b43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63c9b43

Browse files
committed
Cache tick space calculation
1 parent d203807 commit 63c9b43

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/matplotlib/axis.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ def __init__(self, axes, pickradius=15):
654654
# Initialize here for testing; later add API
655655
self._major_tick_kw = dict()
656656
self._minor_tick_kw = dict()
657+
self._tick_space = None
657658

658659
self.cla()
659660
self._set_scale('linear')
@@ -785,6 +786,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
785786
for tick in self.minorTicks:
786787
tick._apply_params(**self._minor_tick_kw)
787788
self.stale = True
789+
self._tick_space = None
788790

789791
@staticmethod
790792
def _translate_tick_kw(kw, to_init_kw=True):
@@ -2339,11 +2341,12 @@ def set_default_intervals(self):
23392341
self.stale = True
23402342

23412343
def get_tick_space(self):
2342-
# TODO: cache this computation
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)
2344+
if self._tick_space is None:
2345+
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
2346+
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
2347+
tick = self._get_tick(True)
2348+
# Having a spacing of at least 2 just looks good.
2349+
size = tick.label1.get_size() * 2.0
2350+
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2351+
self._tick_space = np.floor(length / size)
2352+
return self._tick_space

0 commit comments

Comments
 (0)
0