Skip to content

Commit 44c0bbb

Browse files
committed
FIX: Change default Autodatelocator *interval_multiples*
Also make monthly byranges be 1 and 15
1 parent 0f05cf4 commit 44c0bbb

16 files changed

+58
-1271
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Changed default `AutoDateLocator` kwarg ``interval_multiples`` to ``True``
2+
--------------------------------------------------------------------------
3+
4+
The default value of the tick locator for dates, `.dates.AutoDateLocator`
5+
kwarg ``interval_multiples`` was set to ``False`` which leads to not-nice
6+
looking automatic ticks in many instances. The much nicer
7+
``interval_multiples=True`` is the new default. See below to get the
8+
old behavior back:
9+
10+
.. plot::
11+
12+
import matplotlib.pyplot as plt
13+
import datetime
14+
import matplotlib.dates as mdates
15+
16+
t0 = datetime.datetime(2009, 8, 20, 1, 10, 12)
17+
tf = datetime.datetime(2009, 8, 20, 1, 42, 11)
18+
19+
20+
fig, axs = plt.subplots(1, 2, constrained_layout=True)
21+
ax = axs[0]
22+
ax.axhspan(t0, tf, facecolor="blue", alpha=0.25)
23+
ax.set_ylim(t0 - datetime.timedelta(minutes=3),
24+
tf + datetime.timedelta(minutes=3))
25+
ax.set_title('NEW DEFAULT')
26+
27+
ax = axs[1]
28+
ax.axhspan(t0, tf, facecolor="blue", alpha=0.25)
29+
ax.set_ylim(t0 - datetime.timedelta(minutes=3),
30+
tf + datetime.timedelta(minutes=3))
31+
# old behavior
32+
locator = mdates.AutoDateLocator(interval_multiples=False, )
33+
ax.yaxis.set_major_locator(locator)
34+
ax.yaxis.set_major_formatter(mdates.AutoDateFormatter(locator))
35+
36+
ax.set_title('OLD')
37+
plt.show()

lib/matplotlib/dates.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ class AutoDateLocator(DateLocator):
11581158
locations.
11591159
"""
11601160
def __init__(self, tz=None, minticks=5, maxticks=None,
1161-
interval_multiples=False):
1161+
interval_multiples=True):
11621162
"""
11631163
*minticks* is the minimum number of ticks desired, which is used to
11641164
select the type of ticking (yearly, monthly, etc.).
@@ -1234,6 +1234,9 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
12341234
MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000,
12351235
5000, 10000, 20000, 50000, 100000, 200000, 500000,
12361236
1000000]}
1237+
if interval_multiples:
1238+
self.intervald[DAILY] = [1, 2, 4, 7, 14, 21]
1239+
12371240
self._byranges = [None, range(1, 13), range(1, 32),
12381241
range(0, 24), range(0, 60), range(0, 60), None]
12391242

@@ -1338,7 +1341,10 @@ def get_locator(self, dmin, dmax):
13381341
self._freq = freq
13391342

13401343
if self._byranges[i] and self.interval_multiples:
1341-
byranges[i] = self._byranges[i][::interval]
1344+
if i == 2 and interval == 14:
1345+
byranges[i] = [1, 15]
1346+
else:
1347+
byranges[i] = self._byranges[i][::interval]
13421348
interval = 1
13431349
else:
13441350
byranges[i] = self._byranges[i]
Binary file not shown.

0 commit comments

Comments
 (0)