Skip to content

YearLocator should prefer ticks at the turn of the decade #9838

Closed
@has2k1

Description

@has2k1

Bug summary

YearLocator is agnostic about decades. Ticks at the decades are nicer, so when choosing a starting value in some cases it should prefer to start a the turn of the decade or even mid decade. i.e 1970 instead of 1968, 1965 instead of 1964. This "smart" behaviour should apply when the intervals are factors of 5 and 10.

Code for reproduction

import datetime
import matplotlib.pyplot as plt

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)
# ax.set_xticks(ticks)  # preferred ticks

Actual outcome
bad-date-ticks

Better outcome
good-date-ticks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions