Skip to content

DFLT: change formats for AutoDateFormatter #5445

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

Closed
wants to merge 1 commit into from
Closed
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
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
  • Loading branch information
tacaswell committed Nov 8, 2015
commit f4e6dca76d1a5241567310ce525d0acdc3882980
19 changes: 19 additions & 0 deletions doc/users/whats_new/rcparams.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Configuration (rcParams)
------------------------


+----------------------------+--------------------------------------------------+
| Parameter | Description |
+============================+==================================================+
|`date.autoformatter.year` | foramt string for 'year' scale dates |
+----------------------------+--------------------------------------------------+
|`date.autoformatter.month` | format string for 'month' scale dates |
+----------------------------+--------------------------------------------------+
|`date.autoformatter.day` | format string for 'day' scale dates |
+----------------------------+--------------------------------------------------+
|`date.autoformatter.hour` | format string for 'hour' scale times |
+----------------------------+--------------------------------------------------+
|`date.autoformatter.minute` | format string for 'minute' scale times |
+----------------------------+--------------------------------------------------+
|`date.autoformatter.second` | format string for 'second' scale times |
+----------------------------+--------------------------------------------------+
25 changes: 13 additions & 12 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

from matplotlib.externals import six
from matplotlib.externals.six.moves import xrange, zip

from matplotlib import rcParams
import re
import time
import math
Expand Down Expand Up @@ -629,12 +629,12 @@ class AutoDateFormatter(ticker.Formatter):
format string. The default looks like this::

self.scaled = {
365.0 : '%Y',
30. : '%b %Y',
1.0 : '%b %d %Y',
1./24. : '%H:%M:%S',
1. / (24. * 60.): '%H:%M:%S.%f',
}
DAYS_PER_YEAR: rcParams['date.autoformat.year'],
DAYS_PER_MONTH: rcParams['date.autoformat.month'],
1.0: rcParams['date.autoformat.day'],
1. / HOURS_PER_DAY: rcParams['date.autoformat.hour'],
1. / (MINUTES_PER_DAY): rcParams['date.autoformat.minute'],
1. / (SEC_PER_DAY): rcParams['date.autoformat.second']}


The algorithm picks the key in the dictionary that is >= the
Expand Down Expand Up @@ -685,11 +685,12 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
self._tz = tz
self.defaultfmt = defaultfmt
self._formatter = DateFormatter(self.defaultfmt, tz)
self.scaled = {DAYS_PER_YEAR: '%Y',
DAYS_PER_MONTH: '%b %Y',
1.0: '%b %d %Y',
1. / HOURS_PER_DAY: '%H:%M:%S',
1. / (MINUTES_PER_DAY): '%H:%M:%S.%f'}
self.scaled = {DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
1.0: rcParams['date.autoformatter.day'],
1. / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
1. / (MINUTES_PER_DAY): rcParams['date.autoformatter.minute'],
1. / (SEC_PER_DAY): rcParams['date.autoformatter.second'],}

def __call__(self, x, pos=None):
locator_unit_scale = float(self._locator._get_unit())
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ axes.spines.top : True
polaraxes.grid : True # display grid on polar axes
axes3d.grid : True # display grid on 3d axes

date.autoformatter.year :'%Y'
date.autoformatter.month :'%b %Y'
date.autoformatter.day :'%b %d %Y'
date.autoformatter.hour :'%H:%M:%S'
date.autoformatter.minute :'%H:%M:%S.%f'
date.autoformatter.second :'%H:%M:%S.%f'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to include hours when resolving down to the fractions of a second?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I just noticed that this is the classic style... nm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the ' need to be removed here. They are included verbatim in the result. Even without them, the spaces are preserved.


### TICKS
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
xtick.major.size : 4 # major tick size in points
Expand Down Expand Up @@ -418,7 +425,7 @@ pdf.use14corefonts : False
pgf.debug : False
pgf.texsystem : xelatex
pgf.rcfonts : True
pgf.preamble :
pgf.preamble :

# svg backend params
svg.image_inline : True # write raster image data directly into the svg file
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ def validate_cycler(s):
'polaraxes.grid': [True, validate_bool], # display polar grid or
# not
'axes3d.grid': [True, validate_bool], # display 3d grid
# TODO validate that these are valid datetime format strings
'date.autoformatter.year': ['%Y', six.text_type],
'date.autoformatter.month': ['%Y-%m', six.text_type],
'date.autoformatter.day': ['%Y-%m-%d', six.text_type],
'date.autoformatter.hour': ['%H:%M', six.text_type],
'date.autoformatter.minute': ['%H:%M:%S', six.text_type],
'date.autoformatter.second': ['%H:%M:%S.%f', six.text_type],

#legend properties
'legend.fancybox': [False, validate_bool],
Expand Down
17 changes: 17 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ backend : %(backend)s
# small compared to the minimum absolute
# value of the data.


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

### DATES
# These control the default format strings used in AutoDateFormatter.
# Any valid format datetime format string can be used (see the python
# `datetime` for details). For example using '%%x' will use the locale date representation
# '%%X' will use the locale time representation and '%%c' will use the full locale datetime
# representation.
# These values map to the scales:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to include a note that doubling up on the percent signs is only needed for the rcfile. I am assuming that setting the rcParam directly does not need doubling up on the percent signs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually it's only needed for the template. People's local matplotlibrc's don't need it. This is because the template is first interpolated to set the default backend.

We could use str.format (or some other method for replacing a string) to get around this, which might be less confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the little-known string.Template module might be better. We can
use safe_substitute() to apply formatting for only the one thing that needs
formatting.

On Mon, Nov 9, 2015 at 11:53 AM, Michael Droettboom <
notifications@github.com> wrote:

In matplotlibrc.template
#5445 (comment):

@@ -279,6 +280,22 @@ backend : %(backend)s
#polaraxes.grid : True # display grid on polar axes
#axes3d.grid : True # display grid on 3d axes

+### DATES
+# These control the default format strings used in AutoDateFormatter.
+# Any valid format datetime format string can be used (see the python
+# datetime for details). For example using '%%x' will use the locale date representation
+# '%%X' will use the locale time representation and '%%c' will use the full locale datetime
+# representation.
+# These values map to the scales:

And actually it's only needed for the template. People's local
matplotlibrc's don't need it. This is because the template is first
interpolated to set the default backend.

We could use str.format (or some other method for replacing a string) to
get around this, which might be less confusing.


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/5445/files#r44298777.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WeatherGod indeed on both accounts

# {'year': 365, 'month': 30, 'day': 1, 'hour': 1/24, 'minute': 1 / (24 * 60)}

# date.autoformatter.year : '%%Y'
# date.autoformatter.month : '%%Y-%%m'
# date.autoformatter.day : '%%Y-%%m-%%d'
# date.autoformatter.hour : '%%H:%%M'
# date.autoformatter.minute : '%%H:%%M:%%S'
# date.autoformatter.second : '%%H:%%M:%%S.%%f'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto with the ' here.


### TICKS
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
#xtick.major.size : 4 # major tick size in points
Expand Down