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

Unevenly spaced ticks in plot_date() · Issue #13183 · matplotlib/matplotlib · GitHub

Repository navigation

Unevenly spaced ticks in plot_date() #13183

Closed

Description

Bug report

When plotting with plot_date(), the x axis ticks can be unevenly spaced. It looks like when the tick spacing is less than a month, the start of the month is always present as a tick, which may mean the space between it and the previous tick is small. This can lead to overlapping tick labels and generally poor looking axes and grids.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

start = np.datetime64('2018-01-01', 'D')
end = np.datetime64('2018-04-01', 'D')
dates = np.arange(start, end)
data = np.random.randn(len(dates))

plt.plot_date(dates, data)
plt.grid(True)
plt.gcf().autofmt_xdate()
plt.show()

Actual outcome

Expected outcome

The plot should have evenly spaced gridlines and axis ticks, unless a custom locator has specified otherwise.

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 3.0.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.2
  • Jupyter version (if applicable): n/a
  • Other libraries: matplotlib 1.15.4

Matplotlib, Python and numpy are installed with the OS package manager using the standard Arch Linux repositories.

Activity

  1. jklymak commented on Jan 14, 2019

    Member

    Yes, this was an unintended consequence of #9801. Its been "fixed" by #10841 which is on master...

    Now "fixed" is still different to how it was before, which was (v2.2.3):

    If you want the old behaviour back, you need to do a bit of a song and dance.

    locator = mdates.AutoDateLocator(interval_multiples=False)
    formatter = mdates.AutoDateFormatter(locator)
    
    plt.plot_date(dates, data)
    plt.gca().xaxis.set_major_locator(locator)
    plt.gca().xaxis.set_major_formatter(formatter)
    
    plt.grid(True)
    plt.gcf().autofmt_xdate()
    plt.show()

    I agree that the way things are in 3.0.2 are undersirable because to intervals were not good (i.e. you could get 29, 1 ticks). OTOH, I think the new behaviour (as of master) is better than the 2.2.3 behaviour.

  2. chrisjbillington commented on Jan 14, 2019

    ContributorAuthor

    Oh, that sounds like a great improvement! Snapping the ticks to month edges makes a lot of sense (so long as they're still evenly spaced).

    I have no complaints then, and will close this issue since it's fixed already.

  3. jklymak commented on Jan 14, 2019

    Member

    No problem - sorry for the inconvenience of the bad state right now...

  4. jklymak commented on Jan 14, 2019

    Member

    Oh, sorry, "evenly spaced" for months won't work, of course.... Note the ticks are not evenly spaced above...

  5. chrisjbillington commented on Jan 14, 2019

    ContributorAuthor

    Oh, right, since not all months have the same number of days. Well, it's close enough not to be jarring and is more understandable than exactly even spacing (I guess I didn't realise prior to now that this was a trade-off, I just though matplotlib had been choosing the ticks poorly for no reason).

  6. jklymak commented on Jan 14, 2019

    Member

    OK, thats what "we" decided, but its good to make sure the users are happy too. These things come down to esthetic decisions, and not everyone agrees on the best defaults.

    BTW there will also be a new formatter available, so if you happen to be on master, your opinions on that would be welcome. https://matplotlib.org/devdocs/gallery/ticks_and_spines/date_concise_formatter.html#sphx-glr-gallery-ticks-and-spines-date-concise-formatter-py

  7. chrisjbillington commented on Jan 18, 2019

    ContributorAuthor

    The ConciseDateFormatter looks great! I tried it out and can't think of any complaints against it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL