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

Skip to content

Commit ea62a77

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. - In ticker ensure there is always at least on bin - Axis do not cache the number of ticks so that if the on-screen aspect ratio changes the number of ticks will update correctly.
1 parent c66ea79 commit ea62a77

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
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 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 np.floor(length / size)
23502350
return self._tick_space

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ def set_params(self, **kwargs):
14311431
def bin_boundaries(self, vmin, vmax):
14321432
nbins = self._nbins
14331433
if nbins == 'auto':
1434-
nbins = min(self.axis.get_tick_space(), 9)
1434+
nbins = max(min(self.axis.get_tick_space(), 9), 1)
14351435
scale, offset = scale_range(vmin, vmax, nbins)
14361436
if self._integer:
14371437
scale = max(1, scale)

0 commit comments

Comments
 (0)