Skip to content

Commit 1a6da7b

Browse files
committed
FIX
1 parent 0577839 commit 1a6da7b

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

lib/matplotlib/dates.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -1863,25 +1863,49 @@ def axisinfo(self, unit, axis):
18631863
default_limits=(datemin, datemax))
18641864

18651865

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`
18661869

1867-
def register_converters():
1868-
"""
1869-
Helper to register the date converters.
18701870

1871-
Useful to call if the :rc:`date.converter` or :rc:`date.interval_multiples`
1872-
change.
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.
18731895
"""
1874-
if matplotlib.rcParams['date.converter'] == 'concise':
1896+
global _conv_st
1897+
global _int_mult
1898+
if _conv_st == 'concise':
18751899
converter = ConciseDateConverter
18761900
else:
18771901
converter = DateConverter
18781902

1879-
interval_multiples = matplotlib.rcParams['date.interval_multiples']
1903+
interval_multiples = _int_mult
18801904
units.registry[np.datetime64] = converter(
18811905
interval_multiples=interval_multiples)
18821906
units.registry[datetime.date] = converter(
18831907
interval_multiples=interval_multiples)
18841908
units.registry[datetime.datetime] = converter(
18851909
interval_multiples=interval_multiples)
18861910

1887-
register_converters()
1911+
# _register_converters()

lib/matplotlib/rcsetup.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ def validate_bool_maybe_none(b):
154154
raise ValueError('Could not convert "%s" to bool' % b)
155155

156156

157+
def _validate_date_converter(s):
158+
s = validate_string(s)
159+
try:
160+
import matplotlib.dates as mdates
161+
mdates._set_converter(s)
162+
except Exception as e:
163+
pass
164+
165+
166+
def _validate_date_int_mult(s):
167+
if s is None:
168+
return
169+
s = validate_bool(s)
170+
try:
171+
import matplotlib.dates as mdates
172+
mdates._set_int_mult(s)
173+
except Exception as e:
174+
pass
175+
176+
157177
def _validate_tex_preamble(s):
158178
message = (
159179
f"Support for setting the 'text.latex.preamble' and 'pgf.preamble' "
@@ -1267,9 +1287,9 @@ def _convert_validator_spec(key, conv):
12671287
'date.autoformatter.microsecond': ['%M:%S.%f', validate_string],
12681288

12691289
# 'auto', 'concise', 'auto-noninterval'
1270-
'date.converter': ['auto', validate_string],
1290+
'date.converter': ['auto', _validate_date_converter],
12711291
# for auto date locator, choose interval_multiples
1272-
'date.interval_multiples': [True, validate_bool],
1292+
'date.interval_multiples': [True, _validate_date_int_mult],
12731293

12741294
#legend properties
12751295
'legend.fancybox': [True, validate_bool],

0 commit comments

Comments
 (0)