@@ -654,6 +654,7 @@ def __init__(self, axes, pickradius=15):
654
654
# Initialize here for testing; later add API
655
655
self ._major_tick_kw = dict ()
656
656
self ._minor_tick_kw = dict ()
657
+ self ._tick_space = None
657
658
658
659
self .cla ()
659
660
self ._set_scale ('linear' )
@@ -785,6 +786,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
785
786
for tick in self .minorTicks :
786
787
tick ._apply_params (** self ._minor_tick_kw )
787
788
self .stale = True
789
+ self ._tick_space = None
788
790
789
791
@staticmethod
790
792
def _translate_tick_kw (kw , to_init_kw = True ):
@@ -2339,11 +2341,12 @@ def set_default_intervals(self):
2339
2341
self .stale = True
2340
2342
2341
2343
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