diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 83e13841677a..fe9d23450677 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2706,6 +2706,29 @@ def get_log_range(lo, hi): else: ticklocs = decades + # Add ticks with linear spacing in the linear region for better + # density near zero. + if has_b: + if self.numticks is None: + n_linear = 3 + elif self.numticks <= 0: + n_linear = 0 + else: + n_linear = min(5, self.numticks) + + if n_linear > 0: + linear_vmin = max(vmin, -linthresh) + linear_vmax = min(vmax, linthresh) + + if linear_vmax > linear_vmin: + linear_ticks = np.linspace( + linear_vmin, linear_vmax, n_linear + ) + all_ticks = np.concatenate( + [np.asarray(ticklocs), linear_ticks] + ) + ticklocs = np.sort(np.unique(all_ticks)) + return self.raise_if_exceeds(np.array(ticklocs)) def view_limits(self, vmin, vmax):