Skip to content

ENH: make interval_multiples work for years#9841

Merged
dstansby merged 3 commits into
matplotlib:masterfrom
jklymak:fix-years-autodate
Nov 25, 2017
Merged

ENH: make interval_multiples work for years#9841
dstansby merged 3 commits into
matplotlib:masterfrom
jklymak:fix-years-autodate

Conversation

@jklymak

@jklymak jklymak commented Nov 23, 2017

Copy link
Copy Markdown
Member

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
Copy Markdown
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 jklymak added topic: date handling API: consistency Consistency of the matplotlib API, including naming, behavior, defaults, … labels Nov 23, 2017
@jklymak

jklymak commented Nov 23, 2017

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
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

Labels

API: consistency Consistency of the matplotlib API, including naming, behavior, defaults, … topic: date handling

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