@@ -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,49 @@ 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+ # The following is so that we can set the converter for dates
1867+ # via the validator for the rcParams `date.converter` and
1868+ # `date.interval_multiples`
1869+
1870+
1871+ global _converter
1872+ _conv_st = 'auto'
1873+ global _int_mult
1874+ _int_mult = True
1875+
1876+
1877+ def _set_converter (s ):
1878+ """Called by validator for rcParams date.converter"""
1879+ global _conv_st
1880+ _conv_st = s
1881+ _register_converters ()
1882+
1883+
1884+ def _set_int_mult (b ):
1885+ """Called by validator for rcParams date.interval_multiples"""
1886+ global _int_mult
1887+ _int_mult = b
1888+ _register_converters ()
1889+
1890+
1891+ def _register_converters ():
1892+ """
1893+ Helper to register the date converters when rcParams `date.converter` and
1894+ `date.interval_multiples` are changed. Called by the helpers above.
1895+ """
1896+ global _conv_st
1897+ global _int_mult
1898+ if _conv_st == 'concise' :
1899+ converter = ConciseDateConverter
1900+ else :
1901+ converter = DateConverter
1902+
1903+ interval_multiples = _int_mult
1904+ units .registry [np .datetime64 ] = converter (
1905+ interval_multiples = interval_multiples )
1906+ units .registry [datetime .date ] = converter (
1907+ interval_multiples = interval_multiples )
1908+ units .registry [datetime .datetime ] = converter (
1909+ interval_multiples = interval_multiples )
1910+
1911+ # _register_converters()
0 commit comments