Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd80c9fb

Browse files
authored
Merge pull request#9801 from jklymak/fixdateticklocator
ENH: Change default Autodatelocator *interval_multiples*
2 parents7544c46 +0337883 commitd80c9fb

16 files changed

+62
-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: 12 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,12 @@ 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+
ifinterval_multiples:
1238+
# Swap "3" for "4" in the DAILY list; If we use 3 we get bad
1239+
# tick loc for months w/ 31 days: 1, 4,..., 28, 31, 1
1240+
# If we use 4 then we get: 1, 5, ... 25, 29, 1
1241+
self.intervald[DAILY]= [1,2,4,7,14,21]
1242+
12371243
self._byranges= [None,range(1,13),range(1,32),
12381244
range(0,24),range(0,60),range(0,60),None]
12391245

@@ -1338,7 +1344,11 @@ def get_locator(self, dmin, dmax):
13381344
self._freq=freq
13391345

13401346
ifself._byranges[i]andself.interval_multiples:
1341-
byranges[i]=self._byranges[i][::interval]
1347+
ifi==DAILYandinterval==14:
1348+
# just make first and 15th. Avoids 30th.
1349+
byranges[i]= [1,15]
1350+
else:
1351+
byranges[i]=self._byranges[i][::interval]
13421352
interval=1
13431353
else:
13441354
byranges[i]=self._byranges[i]
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp