Skip to content

Commit 0577839

Browse files
committed
ENH: add rcParam for ConciseDate and interval_multiples
1 parent ef9fc20 commit 0577839

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

lib/matplotlib/dates.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,8 +1784,11 @@ class DateConverter(units.ConversionInterface):
17841784
The 'unit' tag for such data is None or a tzinfo instance.
17851785
"""
17861786

1787-
@staticmethod
1788-
def axisinfo(unit, axis):
1787+
def __init__(self, interval_multiples=True):
1788+
self._interval_multiples = interval_multiples
1789+
super().__init__()
1790+
1791+
def axisinfo(self, unit, axis):
17891792
"""
17901793
Return the `~matplotlib.units.AxisInfo` for *unit*.
17911794
@@ -1794,7 +1797,8 @@ def axisinfo(unit, axis):
17941797
"""
17951798
tz = unit
17961799

1797-
majloc = AutoDateLocator(tz=tz)
1800+
majloc = AutoDateLocator(tz=tz,
1801+
interval_multiples=self._interval_multiples)
17981802
majfmt = AutoDateFormatter(majloc, tz=tz)
17991803
datemin = datetime.date(2000, 1, 1)
18001804
datemax = datetime.date(2010, 1, 1)
@@ -1836,17 +1840,19 @@ class ConciseDateConverter(DateConverter):
18361840
# docstring inherited
18371841

18381842
def __init__(self, formats=None, zero_formats=None, offset_formats=None,
1839-
show_offset=True):
1843+
show_offset=True, interval_multiples=True):
18401844
self._formats = formats
18411845
self._zero_formats = zero_formats
18421846
self._offset_formats = offset_formats
18431847
self._show_offset = show_offset
1848+
self._interval_multiples = interval_multiples
18441849
super().__init__()
18451850

18461851
def axisinfo(self, unit, axis):
18471852
# docstring inherited
18481853
tz = unit
1849-
majloc = AutoDateLocator(tz=tz)
1854+
majloc = AutoDateLocator(tz=tz,
1855+
interval_multiples=self._interval_multiples)
18501856
majfmt = ConciseDateFormatter(majloc, tz=tz, formats=self._formats,
18511857
zero_formats=self._zero_formats,
18521858
offset_formats=self._offset_formats,
@@ -1857,6 +1863,25 @@ def axisinfo(self, unit, axis):
18571863
default_limits=(datemin, datemax))
18581864

18591865

1860-
units.registry[np.datetime64] = DateConverter()
1861-
units.registry[datetime.date] = DateConverter()
1862-
units.registry[datetime.datetime] = DateConverter()
1866+
1867+
def register_converters():
1868+
"""
1869+
Helper to register the date converters.
1870+
1871+
Useful to call if the :rc:`date.converter` or :rc:`date.interval_multiples`
1872+
change.
1873+
"""
1874+
if matplotlib.rcParams['date.converter'] == 'concise':
1875+
converter = ConciseDateConverter
1876+
else:
1877+
converter = DateConverter
1878+
1879+
interval_multiples = matplotlib.rcParams['date.interval_multiples']
1880+
units.registry[np.datetime64] = converter(
1881+
interval_multiples=interval_multiples)
1882+
units.registry[datetime.date] = converter(
1883+
interval_multiples=interval_multiples)
1884+
units.registry[datetime.datetime] = converter(
1885+
interval_multiples=interval_multiples)
1886+
1887+
register_converters()

lib/matplotlib/rcsetup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,11 @@ def _convert_validator_spec(key, conv):
12661266
'date.autoformatter.second': ['%H:%M:%S', validate_string],
12671267
'date.autoformatter.microsecond': ['%M:%S.%f', validate_string],
12681268

1269+
# 'auto', 'concise', 'auto-noninterval'
1270+
'date.converter': ['auto', validate_string],
1271+
# for auto date locator, choose interval_multiples
1272+
'date.interval_multiples': [True, validate_bool],
1273+
12691274
#legend properties
12701275
'legend.fancybox': [True, validate_bool],
12711276
'legend.loc': ['best',

matplotlibrc.template

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
#mathtext.sf: sans
327327
#mathtext.tt: monospace
328328
#mathtext.fallback: cm # Select fallback font from ['cm' (Computer Modern), 'stix'
329-
# 'stixsans'] when a symbol can not be found in one of the
329+
# 'stixsans'] when a symbol can not be found in one of the
330330
# custom math fonts. Select 'None' to not perform fallback
331331
# and replace the missing character by a dummy symbol.
332332
#mathtext.default: it # The default font to use for math.
@@ -431,7 +431,10 @@
431431
#date.autoformatter.minute: %d %H:%M
432432
#date.autoformatter.second: %H:%M:%S
433433
#date.autoformatter.microsecond: %M:%S.%f
434-
434+
## 'auto', 'concise':
435+
#date.converter: 'auto'
436+
## For auto converter whether to use interval_multiples:
437+
#date.interval_multiples: True
435438

436439
## ***************************************************************************
437440
## * TICKS *

0 commit comments

Comments
 (0)