@@ -1166,7 +1166,7 @@ class AutoDateLocator(DateLocator):
1166
1166
locations.
1167
1167
"""
1168
1168
def __init__ (self , tz = None , minticks = 5 , maxticks = None ,
1169
- interval_multiples = False ):
1169
+ interval_multiples = False , spread = "" ):
1170
1170
"""
1171
1171
*minticks* is the minimum number of ticks desired, which is used to
1172
1172
select the type of ticking (yearly, monthly, etc.).
@@ -1208,18 +1208,17 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
1208
1208
The interval is used to specify multiples that are appropriate for
1209
1209
the frequency of ticking. For instance, every 7 days is sensible
1210
1210
for daily ticks, but for minutes/seconds, 15 or 30 make sense.
1211
- You can customize this dictionary by doing::
1211
+ You can customize this dictionary by doing:
1212
1212
1213
1213
locator = AutoDateLocator()
1214
1214
locator.intervald[HOURLY] = [3] # only show every 3 hours
1215
1215
1216
1216
In order to avoid overlapping dates, another dictionary was
1217
1217
created to map date intervals to the format of the date used in
1218
- rcParams. In addition, the default width of figsize from rcparams
1219
- (rcParams["figure.figsize"][0]) is used to get a estimate of the
1220
- number of date ticks we can fit in the axis. This allows customization
1221
- by using rcParam's date format and figsize.
1222
-
1218
+ rcParams. In addition, the figsize and font is used from the axis,
1219
+ and a new setting in rcparams['autodatelocator.spacing'] is added
1220
+ and used to let the user decide when spacing should be used. This
1221
+ was done because rotation at this point in runtime is not known.
1223
1222
"""
1224
1223
DateLocator .__init__ (self , tz )
1225
1224
@@ -1231,7 +1230,6 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
1231
1230
1232
1231
self .maxticks = {YEARLY : 11 , MONTHLY : 12 , DAILY : 11 , HOURLY : 12 ,
1233
1232
MINUTELY : 11 , SECONDLY : 11 , MICROSECONDLY : 8 }
1234
-
1235
1233
if maxticks is not None :
1236
1234
try :
1237
1235
self .maxticks .update (maxticks )
@@ -1261,6 +1259,7 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
1261
1259
MINUTELY : rcParams ['date.autoformatter.minute' ],
1262
1260
SECONDLY : rcParams ['date.autoformatter.second' ],
1263
1261
MICROSECONDLY : rcParams ['date.autoformatter.microsecond' ]}
1262
+ self .spread = spread
1264
1263
1265
1264
self ._byranges = [None , range (1 , 13 ), range (1 , 32 ),
1266
1265
range (0 , 24 ), range (0 , 60 ), range (0 , 60 ), None ]
@@ -1334,12 +1333,25 @@ def get_locator(self, dmin, dmax):
1334
1333
# bysecond, unused (for microseconds)]
1335
1334
byranges = [None , 1 , 1 , 0 , 0 , 0 , None ]
1336
1335
1336
+ axis_name = getattr (self .axis , 'axis_name' , '' )
1337
+ label = getattr (self .axis , 'label' , None )
1338
+ figure = getattr (self .axis , 'figure' , None )
1339
+
1337
1340
# estimated font ratio since our estimation
1338
1341
# is on font size 10
1339
- font_ratio = (rcParams ['font.size' ])/ 10
1342
+ if label is not None :
1343
+ font_ratio = label .get_fontsize ()/ 10
1344
+ else :
1345
+ font_ratio = rcParams ['font.size' ]/ 10
1340
1346
1341
- # a ratio of 10 date characters per inch is 'estimated'
1342
- maxwid = rcParams ["figure.figsize" ][0 ] * 10
1347
+ if figure is not None :
1348
+ width = figure .get_size_inches ()[0 ]
1349
+ else :
1350
+ width = rcParams ["figure.figsize" ][0 ]
1351
+
1352
+ # a ratio of 8 date characters per inch is 'estimated'
1353
+ maxwid = width * 8
1354
+ apply_spread = (rcParams ["autodatelocator.spacing" ] == "generous" )
1343
1355
1344
1356
# Loop over all the frequencies and try to find one that gives at
1345
1357
# least a minticks tick positions. Once this is found, look for
@@ -1356,13 +1368,9 @@ def get_locator(self, dmin, dmax):
1356
1368
continue
1357
1369
1358
1370
# Compute at runtime the size of date label with given format
1359
- try :
1360
- # ensure yaxis ticks are not reduced
1361
- if (self .axis .axis_name == 'x' ):
1362
- date_len = len (dmin .strftime (self .eachtick [freq ])) + 1
1363
- else :
1364
- date_len = 1
1365
- except AttributeError :
1371
+ if (axis_name == 'x' ):
1372
+ date_len = len (dmin .strftime (self .eachtick [freq ]))
1373
+ else :
1366
1374
date_len = 1
1367
1375
1368
1376
# Find the first available interval that doesn't give too many
@@ -1371,7 +1379,8 @@ def get_locator(self, dmin, dmax):
1371
1379
if (num <= interval * (self .maxticks [freq ] - 1 )):
1372
1380
# Using an estmation of characters per inch, reduce
1373
1381
# intervals untill we get no overlaps
1374
- if ((num / interval ) * date_len * font_ratio <= maxwid ):
1382
+ if (((num / interval ) * date_len * font_ratio ) <= maxwid or
1383
+ (not apply_spread )):
1375
1384
break
1376
1385
else :
1377
1386
# We went through the whole loop without breaking, default to
0 commit comments