Skip to content

ENH: Change default Autodatelocator *interval_multiples* #9801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions doc/api/next_api_changes/2018-07-02-JMK.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Changed default `AutoDateLocator` kwarg ``interval_multiples`` to ``True``
--------------------------------------------------------------------------

The default value of the tick locator for dates, `.dates.AutoDateLocator`
kwarg ``interval_multiples`` was set to ``False`` which leads to not-nice
looking automatic ticks in many instances. The much nicer
``interval_multiples=True`` is the new default. See below to get the
old behavior back:

.. plot::

import matplotlib.pyplot as plt
import datetime
import matplotlib.dates as mdates

t0 = datetime.datetime(2009, 8, 20, 1, 10, 12)
tf = datetime.datetime(2009, 8, 20, 1, 42, 11)


fig, axs = plt.subplots(1, 2, constrained_layout=True)
ax = axs[0]
ax.axhspan(t0, tf, facecolor="blue", alpha=0.25)
ax.set_ylim(t0 - datetime.timedelta(minutes=3),
tf + datetime.timedelta(minutes=3))
ax.set_title('NEW DEFAULT')

ax = axs[1]
ax.axhspan(t0, tf, facecolor="blue", alpha=0.25)
ax.set_ylim(t0 - datetime.timedelta(minutes=3),
tf + datetime.timedelta(minutes=3))
# old behavior
locator = mdates.AutoDateLocator(interval_multiples=False, )
ax.yaxis.set_major_locator(locator)
ax.yaxis.set_major_formatter(mdates.AutoDateFormatter(locator))

ax.set_title('OLD')
plt.show()
14 changes: 12 additions & 2 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ class AutoDateLocator(DateLocator):
locations.
"""
def __init__(self, tz=None, minticks=5, maxticks=None,
interval_multiples=False):
interval_multiples=True):
"""
*minticks* is the minimum number of ticks desired, which is used to
select the type of ticking (yearly, monthly, etc.).
Expand Down Expand Up @@ -1234,6 +1234,12 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000,
5000, 10000, 20000, 50000, 100000, 200000, 500000,
1000000]}
if interval_multiples:
# Swap "3" for "4" in the DAILY list; If we use 3 we get bad
# tick loc for months w/ 31 days: 1, 4,..., 28, 31, 1
# If we use 4 then we get: 1, 5, ... 25, 29, 1
self.intervald[DAILY] = [1, 2, 4, 7, 14, 21]

self._byranges = [None, range(1, 13), range(1, 32),
range(0, 24), range(0, 60), range(0, 60), None]

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

if self._byranges[i] and self.interval_multiples:
byranges[i] = self._byranges[i][::interval]
if i == DAILY and interval == 14:
# just make first and 15th. Avoids 30th.
byranges[i] = [1, 15]
else:
byranges[i] = self._byranges[i][::interval]
interval = 1
else:
byranges[i] = self._byranges[i]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/single_date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading