Skip to content

BUG: df.plot makes a shift to the right if frequency multiplies to n > 1 #57594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #58322
natmokval opened this issue Feb 23, 2024 · 5 comments
Open
Tracked by #58322
Assignees
Labels

Comments

@natmokval
Copy link
Contributor

natmokval commented Feb 23, 2024

This bug exists on the latest version of pandas and might be related to the bug reported in #51425.

df.plot DataFrame with PeriodIndex works well for frequency with n=1, while fоr frequency that multiplies on n>1 we have a shift to the right.

Reproducible Examples:

if freq="7h"

from pandas import *
import numpy as np

idx = period_range("01/01/2000", freq='7h', periods=4)
df = DataFrame(
    np.array([0, 1, 0, 1]),
    index=idx,
    columns=["A"],
)
df.plot()
print(df)

the plotting starts from 06:00

res_7h

if freq="2h"

idx = period_range("01/01/2000", freq='2h', periods=4)
df = DataFrame(
    np.array([0, 1, 0, 1]),
    index=idx,
    columns=["A"],
)
df.plot()
print(df)

we have a shift on +1 hour

res_2h

But if freq="h"

idx = period_range("01/01/2000", freq='h', periods=4)
df = DataFrame(
    np.array([0, 1, 0, 1]),
    index=idx,
    columns=["A"],
)
df.plot()
print(df)

the result looks okay:

res_h

Expected Behavior:

I think for both freq="7h" and freq="2h" we should start plotting from the point (00:00, 0.0) as we do for freq="h"

In case DataFrame with DatetimeIndex plotting works correct, e.g.

idx = date_range("01/01/2000", freq='7h', periods=4)
df = DataFrame(
    np.array([0, 1, 0, 1]),
    index=idx,
    columns=["A"],
)
df.plot()
print(df)

output:
res_7h_dr

@natmokval natmokval added Visualization plotting Bug Needs Triage Issue that has not been reviewed by a pandas team member and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2024
@NoelMT
Copy link

NoelMT commented Feb 29, 2024

take

1 similar comment
@Gustaf-Larsson
Copy link

take

@raeef96
Copy link

raeef96 commented Feb 29, 2024

take

@andrefred
Copy link

take

@Aloqeely
Copy link
Member

@natmokval should this be closed now that #58322 is merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants