Skip to content

Commit 59abb91

Browse files
committed
FIX: always use at least 2 ticks and recompute
For extreme aspect-ratio plots the auto ntick logic would decide that no ticks will fit, leading to divide by 0 issue. - This changes the logic in Axis.get_tick_space to have a floor of 1. - also does not cache the number of ticks so that if the on-screen aspect ratio changes the number of ticks will update correctly.
1 parent 4ca39f7 commit 59abb91

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/matplotlib/axis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ def get_tick_space(self):
20042004
# is no more than 3:1
20052005
size = tick.label1.get_size() * 3
20062006
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2007-
self._tick_space = np.floor(length / size)
2007+
return max(1, np.floor(length / size))
20082008
return self._tick_space
20092009

20102010

@@ -2346,5 +2346,5 @@ def get_tick_space(self):
23462346
# Having a spacing of at least 2 just looks good.
23472347
size = tick.label1.get_size() * 2.0
23482348
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
2349-
self._tick_space = np.floor(length / size)
2349+
return max(1, np.floor(length / size))
23502350
return self._tick_space

0 commit comments

Comments
 (0)