Skip to content

Commit f4e6dca

Browse files
committed
DFLT: change formats for AutoDateFormatter
- Use ISO complient formats by default - aded extra level of scale (seconds) - add rcparams for all of these strings closes #4808 closes #4809 closes #5086
1 parent 696ff9f commit f4e6dca

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

doc/users/whats_new/rcparams.rst

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Configuration (rcParams)
2+
------------------------
3+
4+
5+
+----------------------------+--------------------------------------------------+
6+
| Parameter | Description |
7+
+============================+==================================================+
8+
|`date.autoformatter.year` | foramt string for 'year' scale dates |
9+
+----------------------------+--------------------------------------------------+
10+
|`date.autoformatter.month` | format string for 'month' scale dates |
11+
+----------------------------+--------------------------------------------------+
12+
|`date.autoformatter.day` | format string for 'day' scale dates |
13+
+----------------------------+--------------------------------------------------+
14+
|`date.autoformatter.hour` | format string for 'hour' scale times |
15+
+----------------------------+--------------------------------------------------+
16+
|`date.autoformatter.minute` | format string for 'minute' scale times |
17+
+----------------------------+--------------------------------------------------+
18+
|`date.autoformatter.second` | format string for 'second' scale times |
19+
+----------------------------+--------------------------------------------------+

lib/matplotlib/dates.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
from matplotlib.externals import six
116116
from matplotlib.externals.six.moves import xrange, zip
117-
117+
from matplotlib import rcParams
118118
import re
119119
import time
120120
import math
@@ -629,12 +629,12 @@ class AutoDateFormatter(ticker.Formatter):
629629
format string. The default looks like this::
630630
631631
self.scaled = {
632-
365.0 : '%Y',
633-
30. : '%b %Y',
634-
1.0 : '%b %d %Y',
635-
1./24. : '%H:%M:%S',
636-
1. / (24. * 60.): '%H:%M:%S.%f',
637-
}
632+
DAYS_PER_YEAR: rcParams['date.autoformat.year'],
633+
DAYS_PER_MONTH: rcParams['date.autoformat.month'],
634+
1.0: rcParams['date.autoformat.day'],
635+
1. / HOURS_PER_DAY: rcParams['date.autoformat.hour'],
636+
1. / (MINUTES_PER_DAY): rcParams['date.autoformat.minute'],
637+
1. / (SEC_PER_DAY): rcParams['date.autoformat.second']}
638638
639639
640640
The algorithm picks the key in the dictionary that is >= the
@@ -685,11 +685,12 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
685685
self._tz = tz
686686
self.defaultfmt = defaultfmt
687687
self._formatter = DateFormatter(self.defaultfmt, tz)
688-
self.scaled = {DAYS_PER_YEAR: '%Y',
689-
DAYS_PER_MONTH: '%b %Y',
690-
1.0: '%b %d %Y',
691-
1. / HOURS_PER_DAY: '%H:%M:%S',
692-
1. / (MINUTES_PER_DAY): '%H:%M:%S.%f'}
688+
self.scaled = {DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
689+
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
690+
1.0: rcParams['date.autoformatter.day'],
691+
1. / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
692+
1. / (MINUTES_PER_DAY): rcParams['date.autoformatter.minute'],
693+
1. / (SEC_PER_DAY): rcParams['date.autoformatter.second'],}
693694

694695
def __call__(self, x, pos=None):
695696
locator_unit_scale = float(self._locator._get_unit())

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

+8-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ axes.spines.top : True
212212
polaraxes.grid : True # display grid on polar axes
213213
axes3d.grid : True # display grid on 3d axes
214214

215+
date.autoformatter.year :'%Y'
216+
date.autoformatter.month :'%b %Y'
217+
date.autoformatter.day :'%b %d %Y'
218+
date.autoformatter.hour :'%H:%M:%S'
219+
date.autoformatter.minute :'%H:%M:%S.%f'
220+
date.autoformatter.second :'%H:%M:%S.%f'
221+
215222
### TICKS
216223
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
217224
xtick.major.size : 4 # major tick size in points
@@ -418,7 +425,7 @@ pdf.use14corefonts : False
418425
pgf.debug : False
419426
pgf.texsystem : xelatex
420427
pgf.rcfonts : True
421-
pgf.preamble :
428+
pgf.preamble :
422429

423430
# svg backend params
424431
svg.image_inline : True # write raster image data directly into the svg file

lib/matplotlib/rcsetup.py

+7
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ def validate_cycler(s):
965965
'polaraxes.grid': [True, validate_bool], # display polar grid or
966966
# not
967967
'axes3d.grid': [True, validate_bool], # display 3d grid
968+
# TODO validate that these are valid datetime format strings
969+
'date.autoformatter.year': ['%Y', six.text_type],
970+
'date.autoformatter.month': ['%Y-%m', six.text_type],
971+
'date.autoformatter.day': ['%Y-%m-%d', six.text_type],
972+
'date.autoformatter.hour': ['%H:%M', six.text_type],
973+
'date.autoformatter.minute': ['%H:%M:%S', six.text_type],
974+
'date.autoformatter.second': ['%H:%M:%S.%f', six.text_type],
968975

969976
#legend properties
970977
'legend.fancybox': [False, validate_bool],

matplotlibrc.template

+17
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ backend : %(backend)s
265265
# small compared to the minimum absolute
266266
# value of the data.
267267

268+
268269
#axes.unicode_minus : True # use unicode for the minus symbol
269270
# rather than hyphen. See
270271
# http://en.wikipedia.org/wiki/Plus_and_minus_signs#Character_codes
@@ -279,6 +280,22 @@ backend : %(backend)s
279280
#polaraxes.grid : True # display grid on polar axes
280281
#axes3d.grid : True # display grid on 3d axes
281282

283+
### DATES
284+
# These control the default format strings used in AutoDateFormatter.
285+
# Any valid format datetime format string can be used (see the python
286+
# `datetime` for details). For example using '%%x' will use the locale date representation
287+
# '%%X' will use the locale time representation and '%%c' will use the full locale datetime
288+
# representation.
289+
# These values map to the scales:
290+
# {'year': 365, 'month': 30, 'day': 1, 'hour': 1/24, 'minute': 1 / (24 * 60)}
291+
292+
# date.autoformatter.year : '%%Y'
293+
# date.autoformatter.month : '%%Y-%%m'
294+
# date.autoformatter.day : '%%Y-%%m-%%d'
295+
# date.autoformatter.hour : '%%H:%%M'
296+
# date.autoformatter.minute : '%%H:%%M:%%S'
297+
# date.autoformatter.second : '%%H:%%M:%%S.%%f'
298+
282299
### TICKS
283300
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
284301
#xtick.major.size : 4 # major tick size in points

0 commit comments

Comments
 (0)