@@ -2156,13 +2156,13 @@ def tick_values(self, vmin, vmax):
2156
2156
"log-scaled." )
2157
2157
2158
2158
_log .debug ('vmin %s vmax %s' , vmin , vmax )
2159
- vmin = math .log (vmin ) / math .log (b )
2160
- vmax = math .log (vmax ) / math .log (b )
2161
2159
2162
2160
if vmax < vmin :
2163
2161
vmin , vmax = vmax , vmin
2162
+ log_vmin = math .log (vmin ) / math .log (b )
2163
+ log_vmax = math .log (vmax ) / math .log (b )
2164
2164
2165
- numdec = math .floor (vmax ) - math .ceil (vmin )
2165
+ numdec = math .floor (log_vmax ) - math .ceil (log_vmin )
2166
2166
2167
2167
if isinstance (self ._subs , str ):
2168
2168
_first = 2.0 if self ._subs == 'auto' else 1.0
@@ -2181,32 +2181,40 @@ def tick_values(self, vmin, vmax):
2181
2181
if rcParams ['_internal.classic_mode' ] else
2182
2182
(numdec + 1 ) // numticks + 1 )
2183
2183
2184
- # Does subs include anything other than 1?
2184
+ # Does subs include anything other than 1? Essentially a hack to know
2185
+ # whether we're a major or a minor locator.
2185
2186
have_subs = len (subs ) > 1 or (len (subs ) == 1 and subs [0 ] != 1.0 )
2186
2187
2187
- decades = np .arange (math .floor (vmin ) - stride ,
2188
- math .ceil (vmax ) + 2 * stride , stride )
2188
+ decades = np .arange (math .floor (log_vmin ) - stride ,
2189
+ math .ceil (log_vmax ) + 2 * stride , stride )
2189
2190
2190
2191
if hasattr (self , '_transform' ):
2191
2192
ticklocs = self ._transform .inverted ().transform (decades )
2192
2193
if have_subs :
2193
2194
if stride == 1 :
2194
2195
ticklocs = np .ravel (np .outer (subs , ticklocs ))
2195
2196
else :
2196
- # no ticklocs if we have more than one decade
2197
- # between major ticks.
2198
- ticklocs = []
2197
+ # No ticklocs if we have >1 decade between major ticks.
2198
+ ticklocs = np .array ([])
2199
2199
else :
2200
2200
if have_subs :
2201
- ticklocs = []
2202
2201
if stride == 1 :
2203
- for decadeStart in b ** decades :
2204
- ticklocs .extend (subs * decadeStart )
2202
+ ticklocs = np .concatenate (
2203
+ [subs * decade_start for decade_start in b ** decades ])
2204
+ else :
2205
+ ticklocs = np .array ([])
2205
2206
else :
2206
2207
ticklocs = b ** decades
2207
2208
2208
2209
_log .debug ('ticklocs %r' , ticklocs )
2209
- return self .raise_if_exceeds (np .asarray (ticklocs ))
2210
+ if (len (subs ) > 1
2211
+ and stride == 1
2212
+ and ((vmin <= ticklocs ) & (ticklocs <= vmax )).sum () <= 1 ):
2213
+ # If we're a minor locator *that expects at least two ticks per
2214
+ # decade* and the major locator stride is 1 and there's no more
2215
+ # than one minor tick, switch to AutoLocator.
2216
+ return AutoLocator ().tick_values (vmin , vmax )
2217
+ return self .raise_if_exceeds (ticklocs )
2210
2218
2211
2219
def view_limits (self , vmin , vmax ):
2212
2220
'Try to choose the view limits intelligently'
0 commit comments