GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Report date and time of cursor position on a plot_date plot · Issue #7582 · matplotlib/matplotlib

Report date and time of cursor position on a plot_date plot #7582

New issue
Copy link
New issue
Copy link
Closed
Closed
Report date and time of cursor position on a plot_date plot#7582
Copy link
Labels
topic: date handling
Milestone
v3.0.0

Description

@dstansby
dstansby
opened on Dec 7, 2016
Issue body actions

When plotting with DateTime on the x axis, it would be useful to show both the date and time in the cursor position. Currently only the date or time is shown, depending on zoom level.

Example: only the date is shown in bottom left (x=2016-10-16)
screenshot from 2016-12-07 13-51-51

Current master installed using pip, Linux, python 3.5.2

Activity

  1. tacaswell
    added
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    new-contributor-friendly
    on Dec 7, 2016
  2. tacaswell
    added this to the This milestone has been deleted milestone on Dec 7, 2016
  3. tacaswell commented on Dec 7, 2016

    @tacaswell
    tacaswell
    on Dec 7, 2016
    Member
    More actions

    The value shown the bar is by default pulled from the axis Formaterr via the format_data_short method. The default implementation is just the delegate to fomat_data which in turn delegates to __call__ (for historical reasons).

    To trace through the call path here, in backend_bases.NavigationToolbar2.mouse_move (which is hooked up to the mouse move callback) calls Axes.format_coord and puts the result in the GUI msg area. format_coord (in axes/_base.py) calls format_xdata / format_ydata which in turn check if there is a user supplied fmt_xdata or fmt_ydata attributes on the Axes object and if not calls the axis's major formatters format_data_short method.

    The specific work here is:

    • add a format_data_short method to the auto data formatter that uses the next more precise format from what __call__ uses.

    attn @anntzer

  4. anntzer commented on Dec 7, 2016

    @anntzer
    anntzer
    on Dec 7, 2016
    Contributor
    More actions

    I don't think there's a way to make this work for everyone, in the sense that most of the time I'd think you'd only want to use the date OR the time? Probably a doc recipe (which could be, in an ideal world, as simple as ax.xaxis.get_major_formatter().format_data_short = lambda pos: lambda pos: mdates.num2date(pos).strftime("%Y-%m-%d; %H:%M:%S") would be better?

    Anyways, while trying to come up with such a recipe, I found a bunch of issues with datetime and ticker handling.

    • matplotlib.dates should probably export its own strftime function which transparently handles matplotlib timestamps (avoiding the need to call num2date explicitly).

    • The fact that formatters are callable, which I argued against in New Formatter API #5804, makes it possible to write ax.format_xdata = Formatter(...) (e.g. examples/api/date_demo.py), which is a mess as the axes' formatter instance is not correctly set, so format_data_short confusingly doesn't work -- that example really needs to be changed to something like

    import time
    _fmt = mdates.DateFormatter('%Y-%m-%d')
    _fmt.format_data_short = lambda pos: mdates.num2date(pos).strftime("%Y-%m-%d; %H:%M:%S")
    ax.xaxis.set_major_formatter(_fmt)
    

    or alternatively we should just make Axes.format_xdata a property that redirects to Axes.xaxis.major.formatter, so that one can assign to format_xdata and then to format_xdata.format_data_short. (Actually the second solution isn't bad...)
    In other words the pile of redirections going on is really hard to keep track of. (Unlabeling as "easy" and "new-contributor-friendly" for this reason.)

    • examples/api/date_index_formatter.py makes no sense, especially its docstring? Neither plot is labelling or plotting week-ends.
  5. anntzer
    added
    topic: date handling
    and removed
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    new-contributor-friendly
    on Dec 7, 2016
  6. dstansby commented on Dec 7, 2016

    @dstansby
    dstansby
    on Dec 7, 2016
    MemberAuthor
    More actions

    The two use cases I currently frequently encounter are:

    • Looking at a large scale overview (as above), but wanting to know the time of an obvious feature
    • Zooming into data (e.g. the data above) to look at precisely where a feature is, but then loosing information about the date. This means having to zoom back out again to try and find the feature in 'date zoomlevel'.

    Even if you want to know one or the other, showing both doesn't (as far as I can see) impact on this.

  7. anntzer commented on Dec 7, 2016

    @anntzer
    anntzer
    on Dec 7, 2016
    Contributor
    More actions

    My point was that showing too much info could be slightly annoying when the timescale is obviously either very large or very small, but I guess that's not a big cost (and erring on the side of too much info is probably better). In that case I'd suggest always showing cursor data either with the %c (locale) strftime format, or with isoformat().

  8. tacaswell
    modified the milestones: This milestone has been deleted, This milestone has been deleted on Sep 24, 2017
  9. jklymak commented on Mar 24, 2018

    @jklymak
    jklymak
    on Mar 24, 2018
    Member
    More actions

    #10084 does the annoying thing of the big label. Its actually not that annoying.

  10. jklymak
    modified the milestones: This milestone has been deleted, This milestone has been deleted on Mar 24, 2018
  11. WeatherGod commented on Mar 24, 2018

    @WeatherGod
    WeatherGod
    on Mar 24, 2018 via email
    Member
    More actions
    Perhaps this feature needs a complete overhaul? Perhaps supporting a format string with named components? That way, the user can easily customize the output. The hard part will be trying to automatically generate a good default format string.
    …
    On Sat, Mar 24, 2018 at 12:42 AM, Jody Klymak ***@***.***> wrote: #10084 <#10084> does the annoying thing of the big label. Its actually not that annoying. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#7582 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AARy-NnE_qQ_8mmGiPek4TnozYqWfTUCks5thc6lgaJpZM4LGnli> .
  12. jklymak commented on Mar 24, 2018

    @jklymak
    jklymak
    on Mar 24, 2018
    Member
    More actions

    there is a method to change that display, but I forget what its called.

  13. jklymak commented on Mar 24, 2018

    @jklymak
    jklymak
    on Mar 24, 2018
    Member
    More actions

    Ax.format_cursor

  14. dstansby commented on Apr 8, 2018

    @dstansby
    dstansby
    on Apr 8, 2018
    MemberAuthor
    More actions

    I think this has improved enough for me to close the original issue now.

  15. dstansby
    closed this as completedon Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: date handling

    Type

    No type

    Projects

    No projects

      Milestone

      • v3.0.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.