Skip to content

Reduce AutoDateFormatter precision when possible #4809

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
Closed
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
19 changes: 10 additions & 9 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,13 @@ 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 : '%Y',
DAYS_PER_MONTH : '%b %Y',
1.0 : '%b %d %Y',
1. / HOURS_PER_DAY : '%H:%M',
1. / SEC_PER_DAY : '%H:%M:%S',
1. / MUSECONDS_PER_DAY : '%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.

This part is a doc-string, so perhaps it doesn't make sense to use the global variables here?

Copy link
Author

Choose a reason for hiding this comment

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

I would say it makes the documentation more clear like this? Also, expanding MUSECONDS_PER_DAY would result in 1. / (24 * 60 * 60 * 1000000), which struck me as overly complicated. But I'm happy to change back to numbers if you think that would be better?

Copy link
Member

Choose a reason for hiding this comment

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

fair enough. I'll let others weigh in with their preference.

Copy link
Member

Choose a reason for hiding this comment

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

I think the globals as much more readable.

}

The algorithm picks the key in the dictionary that is >= the
current scale and uses that format string. You can customize this
Expand Down Expand Up @@ -688,8 +688,9 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
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'}
1. / HOURS_PER_DAY: '%H:%M',
1. / SEC_PER_DAY: '%H:%M:%S',
1. / MUSECONDS_PER_DAY: '%H:%M:%S.%f'}

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