@@ -1978,12 +1978,12 @@ def __init__(self, nbins=None, **kwargs):
1978
1978
automatically determined based on the length of the axis.
1979
1979
1980
1980
steps : array-like, optional
1981
- Sequence of nice numbers starting with 1 and ending with 10;
1982
- e.g., [1, 2, 4, 5, 10], where the values are acceptable
1983
- tick multiples. i.e. for the example, 20, 40, 60 would be
1984
- an acceptable set of ticks, as would 0.4, 0.6, 0.8, because
1985
- they are multiples of 2. However, 30, 60, 90 would not
1986
- be allowed because 3 does not appear in the list of steps.
1981
+ Sequence of acceptable tick multiples, starting with 1 and
1982
+ ending with 10. For example, if ``steps= [1, 2, 4, 5, 10]``,
1983
+ ``20, 40, 60`` or ``0.4, 0.6, 0.8`` would be possible
1984
+ sets of ticks because they are multiples of 2.
1985
+ `` 30, 60, 90`` would not be generated because 3 does not
1986
+ appear in this example list of steps.
1987
1987
1988
1988
integer : bool, default: False
1989
1989
If True, ticks will take only integer values, provided at least
@@ -2092,27 +2092,28 @@ def _raw_ticks(self, vmin, vmax):
2092
2092
scale , offset = scale_range (vmin , vmax , nbins )
2093
2093
_vmin = vmin - offset
2094
2094
_vmax = vmax - offset
2095
- raw_step = (_vmax - _vmin ) / nbins
2096
2095
steps = self ._extended_steps * scale
2097
2096
if self ._integer :
2098
2097
# For steps > 1, keep only integer values.
2099
2098
igood = (steps < 1 ) | (np .abs (steps - np .round (steps )) < 0.001 )
2100
2099
steps = steps [igood ]
2101
2100
2102
- istep = np .nonzero (steps >= raw_step )[0 ][0 ]
2103
-
2104
- # Classic round_numbers mode may require a larger step.
2101
+ raw_step = ((_vmax - _vmin ) / nbins )
2102
+ large_steps = steps >= raw_step
2105
2103
if mpl .rcParams ['axes.autolimit_mode' ] == 'round_numbers' :
2106
- for istep in range (istep , len (steps )):
2107
- step = steps [istep ]
2108
- best_vmin = (_vmin // step ) * step
2109
- best_vmax = best_vmin + step * nbins
2110
- if best_vmax >= _vmax :
2111
- break
2112
-
2113
- # This is an upper limit; move to smaller steps if necessary.
2114
- for istep in reversed (range (istep + 1 )):
2115
- step = steps [istep ]
2104
+ # Classic round_numbers mode may require a larger step.
2105
+ # Get first multiple of steps that are <= _vmin
2106
+ floored_vmins = (_vmin // steps ) * steps
2107
+ floored_vmaxs = floored_vmins + steps * nbins
2108
+ large_steps = large_steps & (floored_vmaxs >= _vmax )
2109
+
2110
+ # Find index of smallest large step
2111
+ istep = np .nonzero (large_steps )[0 ][0 ]
2112
+
2113
+ # Start at smallest of the steps greater than the raw step, and check
2114
+ # if it provides enough ticks. If not, work backwards through
2115
+ # smaller steps until one is found that provides enough ticks.
2116
+ for step in steps [:istep + 1 ][::- 1 ]:
2116
2117
2117
2118
if (self ._integer and
2118
2119
np .floor (_vmax ) - np .ceil (_vmin ) >= self ._min_n_ticks - 1 ):
0 commit comments