Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Incorrect X-axis scaling with date values #28341

Closed
@pm13

Description

@pm13

Bug summary

In matplotlib 3.9.0, when plotting dates on the X-axis, calling axhspan unexpectedly expands the X-axis range from 1970 to 2024. This behavior did not occur in version 3.8.4, where the X-axis correctly ranges from 2020 to 2024.

Code for reproduction

import datetime
import matplotlib.pyplot as plt

x = [datetime.date(year, 1, 1) for year in range(2020, 2024)]
y = range(4)

plt.plot(x, y)
plt.axhspan(1, 2)

Actual outcome

3 9 0

Expected outcome

3 8 4

Additional information

No response

Operating system

Fedora

Matplotlib Version

3.9.0

Matplotlib Backend

inline or Agg

Python version

3.12.3

Jupyter version

4.2.1

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions