Skip to content
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

BUG: pd_df.plot issue: plotting several pd_df on the same figure, sometimes works, sometimes not #54561

Closed
2 of 3 tasks
jerabaul29 opened this issue Aug 15, 2023 · 3 comments
Closed
2 of 3 tasks
Labels

Comments

@jerabaul29
Copy link

jerabaul29 commented Aug 15, 2023

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

See the notebooks at:

Basically, all works fine in the first notebook. In the second notebook, doing exactly the same trick of .ploting twice on the same figure, I get an empty figure.

Issue Description

As visible in https://github.com/jerabaul29/public_bug_reports/blob/main/pandas/2023_08_15/SimpleScriptGetTideCurrentTimeseries.ipynb :

# this should work but plot is empty!
fig = plt.figure()
ax = plt.gca()
#
mask_pytmd = get_mask(df_pytmd, utc_timestamp_start, utc_timestamp_stop)
df_pytmd.loc[mask_pytmd].plot(x="utc_timestamp", y="pytmd_u", ax=ax)
#
mask_xr_obs = get_mask(df_xr_obs, utc_timestamp_start, utc_timestamp_stop)
df_xr_obs.loc[mask_xr_obs].plot(x="utc_timestamp", y=["xr_obs_u"], ax=ax)
#
plt.show()

Expected Behavior

This should plot both curves on the same figure.

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.11.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-78-generic
Version : #85~20.04.1-Ubuntu SMP Mon Jul 17 09:42:39 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.14.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : 2023.6.0
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : 2023.7.0
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@jerabaul29 jerabaul29 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 15, 2023
@lithomas1
Copy link
Member

lithomas1 commented Aug 16, 2023

Can you please cut down your example to be minimal and copy-pastable?
(e.g. try constructing a DataFrame with the relevant data already instead of loading it in)

I'm not going to run code involving pickle files due to security concerns with pickle.

@lithomas1 lithomas1 added Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 16, 2023
@jerabaul29
Copy link
Author

I updated dumping the pd df:s as csv. Now running the exact same code, I get a figure with 2 curves, but the x-axis is messed up (both curves should last for nearly the same duration), and the x-ticks look weird (the x-ticks looked much better in the previous plot of the exact same dataset). I do not know if this is considered a bug or not, but from a user perspective it feels a bit brittle, so if this could be improved on / a way to do this better could be provided, this would be very useful :) .

See:

https://github.com/jerabaul29/public_bug_reports/blob/main/pandas/2023_08_15/SimpleScriptGetTideCurrentTimeseries_csv.ipynb

The code to run reduces to:

import pandas as pd
import datetime
import matplotlib.pyplot as plt

pd.show_versions()

df_pytmd = pd.read_csv("./df_pytmd.csv")
df_xr_obs = pd.read_csv("./df_xr_obs.csv")

# plotting...

# keeping this for now, to report issue to pandas

# this should work but plot is empty!
# actually not empty any longer, but looks ugly with the X-axis!
fig = plt.figure()
ax = plt.gca()
#
df_pytmd.plot(x="utc_timestamp", y=["pytmd_u"], ax=ax)
#
df_xr_obs.plot(x="utc_timestamp", y=["xr_obs_u"], ax=ax)
#
plt.show()

# while both plots individually work

# plot 1
fig = plt.figure()
ax = plt.gca()
#
df_pytmd.plot(x="utc_timestamp", y="pytmd_u", ax=ax)
#
plt.show()

# plot 2
fig = plt.figure()
ax = plt.gca()
#
df_xr_obs.plot(x="utc_timestamp", y=["xr_obs_u"], ax=ax)
#
plt.show()

@mroeschke mroeschke added Visualization plotting and removed Needs Info Clarification about behavior needed to assess issue labels Aug 26, 2024
@mroeschke
Copy link
Member

Thanks for the report, but for testing, we would need a more minimal example not involving files for unit testing concerns. Going to close for now but happy to reopen if you're able to able to reproduce with synthetic, in memory data

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

3 participants