Skip to content

[Bug]: Redundant month in ConciseDateFormatter offset text when it displays days and months #24982

@persep

Description

@persep

Bug summary

When you make a plot with the ConciseDateFormatter that shows on the x axis days and months the offset_string also shows the month (with the year) which I think is redundant because you only need the year

Code for reproduction

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

fig, ax = plt.subplots()

d1 = datetime.datetime(1997, 1, 1)
d2 = d1 + datetime.timedelta(weeks=520)

locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)

ax.plot([d1, d2], [0, 0])

ax.set_xlim(d1, d1 + datetime.timedelta(weeks=3))
ax.set_xlim(d1 + datetime.timedelta(weeks=1),
                d1 + datetime.timedelta(weeks=10))

plt.show()

Actual outcome

image

Expected outcome

image

Additional information

When the ConciseDateFormatter was proposed here you can see the same expected behavior:

image

Operating system

Ubuntu 22.04.1 LTS

Matplotlib Version

3.6.2

Matplotlib Backend

agg

Python version

3.10.6

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: date handling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions