@@ -2165,13 +2165,13 @@ def tick_values(self, vmin, vmax):
2165
2165
"log-scaled." )
2166
2166
2167
2167
_log .debug ('vmin %s vmax %s' ,vmin ,vmax )
2168
- vmin = math .log (vmin )/ math .log (b )
2169
- vmax = math .log (vmax )/ math .log (b )
2170
2168
2171
2169
if vmax < vmin :
2172
2170
vmin ,vmax = vmax ,vmin
2171
+ log_vmin = math .log (vmin )/ math .log (b )
2172
+ log_vmax = math .log (vmax )/ math .log (b )
2173
2173
2174
- numdec = math .floor (vmax )- math .ceil (vmin )
2174
+ numdec = math .floor (log_vmax )- math .ceil (log_vmin )
2175
2175
2176
2176
if isinstance (self ._subs ,str ):
2177
2177
_first = 2.0 if self ._subs == 'auto' else 1.0
@@ -2195,32 +2195,40 @@ def tick_values(self, vmin, vmax):
2195
2195
while numdec // stride + 1 > numticks :
2196
2196
stride += 1
2197
2197
2198
- # Does subs include anything other than 1?
2198
+ # Does subs include anything other than 1? Essentially a hack to know
2199
+ # whether we're a major or a minor locator.
2199
2200
have_subs = len (subs )> 1 or (len (subs )== 1 and subs [0 ]!= 1.0 )
2200
2201
2201
- decades = np .arange (math .floor (vmin )- stride ,
2202
- math .ceil (vmax )+ 2 * stride ,stride )
2202
+ decades = np .arange (math .floor (log_vmin )- stride ,
2203
+ math .ceil (log_vmax )+ 2 * stride ,stride )
2203
2204
2204
2205
if hasattr (self ,'_transform' ):
2205
2206
ticklocs = self ._transform .inverted ().transform (decades )
2206
2207
if have_subs :
2207
2208
if stride == 1 :
2208
2209
ticklocs = np .ravel (np .outer (subs ,ticklocs ))
2209
2210
else :
2210
- # no ticklocs if we have more than one decade
2211
- # between major ticks.
2212
- ticklocs = []
2211
+ # No ticklocs if we have >1 decade between major ticks.
2212
+ ticklocs = np .array ([])
2213
2213
else :
2214
2214
if have_subs :
2215
- ticklocs = []
2216
2215
if stride == 1 :
2217
- for decadeStart in b ** decades :
2218
- ticklocs .extend (subs * decadeStart )
2216
+ ticklocs = np .concatenate (
2217
+ [subs * decade_start for decade_start in b ** decades ])
2218
+ else :
2219
+ ticklocs = np .array ([])
2219
2220
else :
2220
2221
ticklocs = b ** decades
2221
2222
2222
2223
_log .debug ('ticklocs %r' ,ticklocs )
2223
- return self .raise_if_exceeds (np .asarray (ticklocs ))
2224
+ if (len (subs )> 1
2225
+ and stride == 1
2226
+ and ((vmin <= ticklocs )& (ticklocs <= vmax )).sum ()<= 1 ):
2227
+ # If we're a minor locator *that expects at least two ticks per
2228
+ # decade* and the major locator stride is 1 and there's no more
2229
+ # than one minor tick, switch to AutoLocator.
2230
+ return AutoLocator ().tick_values (vmin ,vmax )
2231
+ return self .raise_if_exceeds (ticklocs )
2224
2232
2225
2233
def view_limits (self ,vmin ,vmax ):
2226
2234
'Try to choose the view limits intelligently'