Skip to content

BUG: Plotting with PeriodIndex with frequency > 1 leads to wrong x-axis #51425

Open
@gorold

Description

@gorold

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

from datetime import datetime, timedelta
import pandas as pd

date_today = datetime(2023, 2, 2, 0, 0)
days = pd.date_range(date_today, date_today + timedelta(minutes=10), freq='5T').to_period()
data = np.random.randint(1, high=100, size=len(days))
df = pd.DataFrame({'index': days, 'data': data}).set_index("index")

display(df)

df.plot()

df.index = df.index.to_timestamp()
df.plot()

Issue Description

Plotting with PeriodIndex with frequencies larger than 1 (e.g. 5T, 60T, ...) plots the x-axis as the end of the period, rather than the start of the period.

The created dataframe:
Screenshot 2023-02-16 at 2 44 15 pm

Plotting directly:
periodindex

Changing to DatetimeIndex:
timestamp
ng)

Expected Behavior

The expected behaviour should be that what is shown for DatetimeIndex.

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.9.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.133+
Version : #1 SMP Sun Sep 11 08:45:44 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
setuptools : 67.1.0
pip : 23.0
Cython : None
pytest : None
hypothesis : 6.56.4
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.5
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : None
fsspec : 2023.1.0
gcsfs : None
matplotlib : 3.6.3
numba : 0.56.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : 2.0.2
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions