Description
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
import pandas as pd
num_rows = 10
data = {
"datetime": [pd.to_datetime("now") + pd.Timedelta(hours=i) * i for i in range(num_rows)],
"values": (i for i in range(10)),
}
df = pd.DataFrame(data)
df["time"] = df.datetime.diff().fillna(pd.Timedelta(0)).cumsum()
# plot with datetime index
df.set_index("datetime")["values"].plot(style=".-")
# plot with timedelta index
df.set_index("time")["values"].plot(style=".-")
Issue Description
Plotting the same data with a datetime index or timedelta index yield different plot results. In the first case equispaced x-ticks are created whereas in the latter the time relation isn't considered.
Expected Behavior
I expected the same plot simply with different x-axis labels.
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.12.5.final.0
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 75.1.0
pip : 24.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.27.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.9.2
numba : 0.60.0
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None