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

Conversation

matthijskooijman
Copy link

Previously, the AutoDateFormatter would choose a format with second or
microsecond precision, even when the ticks were significantly coarser
than that. The resulting extra precision looks weird and can clutter the
display (especially with the long microsecond display).

This commit changes the default scale to format dictionary, which now
works as follows:

  • Use microsecond precision when the ticks are less than a second apart
  • Use second precision when the ticks are seconds apart
  • Use minute precision when the ticks are minutes or hours apart
  • Use day-precision, month or year precision when the ticks are days or more
    apart (unchanged).

Note that there is no point in displaying only the hour when the ticks are
hours apart, since then it won't be immediately clear that a time is being
displayed. Adding the (technically superfluous) :00 for the minutes should
make it immediately obvious that a time is being displayed, which is why the
minute precision should also be used when the ticks are hours apart.

While updating the documentation for this change, it was also changed to use
symbolic constants instead of hardcoded numbers. This should make it more clear
what the intention is.

Closes: #4808

Previously, the AutoDateFormatter would choose a format with second or
microsecond precision, even when the ticks were significantly coarser
than that. The resulting extra precision looks weird and can clutter the
display (especially with the long microsecond display).

This commit changes the default scale to format dictionary, which now
works as follows:

 - Use microsecond precision when the ticks are less than a second apart
 - Use second precision when the ticks are seconds apart
 - Use minute precision when the ticks are minutes or hours apart
 - Use day-precision, month or year precision when the ticks are days or more
   apart (unchanged).

Note that there is no point in displaying only the hour when the ticks are
hours apart, since then it won't be immediately clear that a time is being
displayed. Adding the (technically superfluous) :00 for the minutes should
make it immediately obvious that a time is being displayed, which is why the
minute precision should also be used when the ticks are hours apart.

While updating the documentation for this change, it was also changed to use
symbolic constants instead of hardcoded numbers. This should make it more clear
what the intention is.

Closes: matplotlib#4808
@matthijskooijman
Copy link
Author

Note that this pullrequest has not been tested as-is, since I don't have time right now to set up a full matplotlib build from git. I did test the changes backported into 1.4.3, which works as expected.

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.

@tacaswell tacaswell added this to the Color overhaul milestone Jul 28, 2015
@mdboom mdboom modified the milestones: Color overhaul, next major release (2.0) Oct 8, 2015
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Nov 8, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
@tacaswell tacaswell self-assigned this Nov 8, 2015
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 11, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 16, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 16, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 17, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 23, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 25, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 27, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Nov 27, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 14, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 14, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
@mdboom
Copy link
Member

mdboom commented Dec 14, 2015

Would it make sense to just combine this with #5445, @tacaswell?

mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 14, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 17, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 31, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
mdboom pushed a commit to mdboom/matplotlib that referenced this pull request Dec 31, 2015
 - Use ISO complient formats by default
 - aded extra level of scale (seconds)
 - add rcparams for all of these strings

closes matplotlib#4808 closes matplotlib#4809 closes matplotlib#5086
@tacaswell tacaswell closed this in 1849626 Jan 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants