Skip to content

BUG: register_matplotlib_converters leads to wrong datetime interpretation with matplotlib 3.3 #35350

Closed
@ZahlGraf

Description

@ZahlGraf
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import datetime
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter

from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

t = [
    datetime.datetime(2022, 12, 31, 0, 0), 
    datetime.datetime(2022, 11, 30, 0, 0), 
    datetime.datetime(2022, 10, 31, 0, 0),
]
s = [0.0, 0.1, 0.2]

fig, ax = plt.subplots()
ax.plot_date(x=t, y=s)
ax.xaxis.set_major_formatter(DateFormatter("%b '%y"))

plt.xticks(rotation=90)
plt.show()

Problem description

The years in the plot are now 91 and 92.

grafik

Note: With matplotlib 3.2.2 (the last stable release) the error is not there. So I guess this is a bug due to an api change inside matplotlib 3.3.0.

Expected Output

I expects the year 22 and 23 like in this image:

grafik

The second image can be produced by deleting the call to register_matplotlib_converters()

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.6.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
machine          : AMD64
processor        : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : None.None

pandas           : 1.0.5
numpy            : 1.19.0
pytz             : 2020.1
dateutil         : 2.8.1
pip              : 19.2.3
setuptools       : 41.2.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.3.0
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
pytest           : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
numba            : None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions