Skip to content

ENH: make interval_multiples work for years #9841

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

Merged
merged 3 commits into from
Nov 25, 2017

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Nov 23, 2017

PR Summary

If dates.AutoTickLocator was on the YEARLY frequency, it didn't respect the interval_multiples kwarg. This changes that by using the YearlyLocator if interval_multiples=True

(Of course I still think dateticks should be overhauled, but thats a bigger project)

Fixes #9838

import datetime
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np

x = [datetime.datetime(1966, 1, 1),
     datetime.datetime(2017, 1, 1)]

ticks = [datetime.datetime(i, 1, 1)
        for i in range(1970, 2020, 10)]

y = np.arange(len(x))
fig, ax = plt.subplots()
ax.plot_date(x, y)
locator = mdates.AutoDateLocator(interval_multiples=True)
ax.xaxis.set_major_locator(locator)
plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant

@tacaswell tacaswell added this to the v2.2 milestone Nov 23, 2017
@tacaswell
Copy link
Member

👍 in principle. Can you add a test (just setting it up and asking what the ticks are rather than an image test)? Might be worth a whats_new update, or just a callout in the some date-related documentation to make it discoverable.

@jklymak jklymak changed the title make interval_multiples work for years WIP. make interval_multiples work for years Nov 23, 2017
@jklymak
Copy link
Member Author

jklymak commented Nov 23, 2017

@tacaswell I updated the doc at the top (which was out of date, BTW), and also will add to #9827 where I discuss DateLocators.

@jklymak jklymak changed the title WIP. make interval_multiples work for years ENH: make interval_multiples work for years Nov 23, 2017
@tacaswell
Copy link
Member

There is trailing whitespace.

@dstansby dstansby merged commit 982254c into matplotlib:master Nov 25, 2017
has2k1 added a commit to has2k1/mizani that referenced this pull request Dec 2, 2017
The restriction in the first place was trying to make up
for what was actually a bug in Matplotlib. It was fixed in
matplotlib/matplotlib#9841.
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
@jklymak jklymak deleted the fix-years-autodate branch March 5, 2019 16:09
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.

YearLocator should prefer ticks at the turn of the decade
4 participants