FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

AutoDateFormatter shows too much precision · Issue #4808 · matplotlib/matplotlib · GitHub

Repository navigation

AutoDateFormatter shows too much precision #4808

Closed

Description

When trying to plot some date-based values, I noticed that the default labels show too much precision. I was trying to plot some data points over a minutes to hours interval, and the default plot kept showing times using a micro-second precision. Given that the major ticks were minutes apart, this seems overkill to me (and the extra digits quickly clutter the display, making the labels overlap).

Diving into the code, it seems the default "scaled" member of the
AutoDateFormatter, which determines what formats to use when, can be
improved. Currently, it:

  • Uses microsecond precision when the ticks are minutes or less apart.
  • Uses second precision when the ticks are hours apart
  • Uses day-precision, month or year precision when the ticks are days
    or more apart (these are fine, so I lumped them together).

I think it should be like this:

  • Use microsecond precision when the ticks 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 prevent this, which is why the minute precision should
also be used when the ticks are hours apart.

The above would be implemented by the following change (documentation
not updated yet):

@@ -563,8 +573,9 @@
         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())

Does this sound reasonable?

Activity

  1. WeatherGod commented on Jul 28, 2015

    Member

    This might be perfect for the upcoming v2.0 style-change release, but I
    wouldn't be against it being treated as a bugfix and put into 1.5 (to be
    released soon). Could you put together a Pull Request with this change?
    This way, we can see exactly how this looks as it would (hopefully) break
    some unit tests.

    On Tue, Jul 28, 2015 at 10:40 AM, Matthijs Kooijman <
    notifications@github.com> wrote:

    When trying to plot some date-based values, I noticed that the default
    labels show too much precision. I was trying to plot some data points over
    a minutes to hours interval, and the default plot kept showing times using
    a micro-second precision. Given that the major ticks were minutes apart,
    this seems overkill to me (and the extra digits quickly clutter the
    display, making the labels overlap).

    Diving into the code, it seems the default "scaled" member of the
    AutoDateFormatter, which determines what formats to use when, can be
    improved. Currently, it:

    • Uses microsecond precision when the ticks are minutes or less apart.
    • Uses second precision when the ticks are hours apart
    • Uses day-precision, month or year precision when the ticks are days
      or more apart (these are fine, so I lumped them together).

    I think it should be like this:

    • Use microsecond precision when the ticks 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 prevent this, which is why the minute precision should
    also be used when the ticks are hours apart.

    The above would be implemented by the following change (documentation
    not updated yet):

    @@ -563,8 +573,9 @@
    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())

    Does this sound reasonable?

    —
    Reply to this email directly or view it on GitHub
    #4808.

  2. added a commit that references this issue on Jul 28, 2015
    08b7821
  3. matthijskooijman commented on Jul 28, 2015

    Author

    Thanks for your reply, I created a PR just now.

  4. added this to the milestone on Jul 28, 2015
  5. modified the milestones: , on Oct 8, 2015
  6. added a commit that references this issue on Nov 8, 2015
    f4e6dca
  7. self-assigned this
    on Nov 8, 2015
  8. added 7 commits that reference this issue on Nov 11, 2015
    9995d68
    9fe9eae
    72a6988
    1c92b74
    f529634
    41c2a7c
    8d6eedc
  9. ahed87 commented on Nov 27, 2015

    Contributor

    Hi,
    a bit of hi-jack, but...

    Quite some time ago I was making a plot with dates, and tried to get the axis to format milliseconds.
    I could not get that working, there were some comments around that it was not possible, so I stopped trying, and made sure that it was only second resolution which became very coarse, but displaying the microseconds just added too many digits for readability.

    Would it be possible to add milliseconds to the formatter, or at least the choise of digits in the formatter.
    It's kind of a large step to go from seconds to microseconds,
    I think it would be appreciated if milliseconds appeared before microseconds.

  10. added a commit that references this issue on Nov 27, 2015
    755b44e
  11. added 4 commits that reference this issue on Dec 14, 2015
    395ec58
    10f8733
    d6701eb
    1a4d003
  12. added a commit that references this issue on Dec 19, 2015
    1849626
  13. added 2 commits that reference this issue on Dec 31, 2015
    d96e7b9
    c84966c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL