-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Subplot data is lost when sharex=True and latter DatetimeIndex has higher frequency #55110
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
Comments
Hey there, I was attempting to run your test script on |
Ok, before the plotting commands, try running:
Does that help? |
Unfortunately no. >>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import pandas as pd
>>> (_, axs) = plt.subplots(2, 1, sharex=True)
>>> t0 = pd.date_range("2023-09-12 10:00", periods=48, freq="1H")
>>> t1 = pd.date_range("2023-09-12 10:00", periods=12*48, freq="5Min")
>>> x0 = pd.Series(
... index=t0,
... data=np.random.randn(48),
... )
>>> x1 = pd.Series(
... index=t1,
... data=np.random.randn(12*48),
... )
>>> plt.ion()
<contextlib.ExitStack object at 0x144769c50>
>>> x0.plot(ax=axs[0])
<Axes: >
>>> x1.plot(ax=axs[1])
<Axes: > |
How about |
This is related to #52895 (and the other issues linked in #52895 (comment)), the issue is that pandas plots periodic datetime ranges in a different unit (which will work okay if nothing else is changed about the plot, but once there are multiple axes/plots involved or any other matplotlib date utilites are used, everything breaks down). It seems to look okay after fixed to not plot in different units: |
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
Issue Description
When using subplots and sharing x axis, if a latter plot has a higher temporal resolution, the former plot gets emptied.
(Sorry, I checked the box that I've tested with the latest version of pandas but unfortunately I was able to test only 2.0.3 for now. I'll see if I can manage to test 2.1.0 some other day perhaps.)
Expected Behavior
Both plots should show data:
Installed Versions
INSTALLED VERSIONS
commit : 0f43794
python : 3.11.4.final.0
python-bits : 64
OS : Linux
OS-release : 6.3.3
Version : #1-NixOS SMP PREEMPT_DYNAMIC Wed May 17 12:02:08 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.3
numpy : 1.25.1
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.4.0.post0
pip : None
Cython : 0.29.36
pytest : 7.4.0
hypothesis : 6.68.2
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.5
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
snappy : None
sqlalchemy : 2.0.19
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2022.7
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: