Skip to content

BUG: OverflowError when plotting with sharex=True #40470

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
2 of 3 tasks
shaharkadmiel opened this issue Mar 16, 2021 · 4 comments
Open
2 of 3 tasks

BUG: OverflowError when plotting with sharex=True #40470

shaharkadmiel opened this issue Mar 16, 2021 · 4 comments
Labels
Bug Datetime Datetime data dtype Visualization plotting

Comments

@shaharkadmiel
Copy link

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

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


I have two datasets from different sources. They span more or less the same time, contain different data, sampled at different rate.

I am trying to plot these on two subplots with a shared x axis.

Making sample data:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

time1 = pd.date_range(
    '2020-11-08T09:31:06', '2020-12-01T22:59:59', freq='S', tz='UTC'
)

df1 = pd.DataFrame(
    np.sin(2 * np.pi * 1e-5 * np.arange(time1.size)),
    index=time1,
    columns=['x1']
)

time2 = pd.date_range(
    '2020-11-08T09:32:00', '2020-12-01T22:58:00', freq='D', tz='UTC'
)

df2 = pd.DataFrame(
    np.sin(2 * np.pi * 1e-1 * np.arange(time2.size)),
    index=time2,
    columns=['x2']
)

Minimal plotting example:

fig, (ax1, ax2) = plt.subplots(2, sharex=True)
fig.subplots_adjust(0, 0, 1, 1, hspace=0.15)


df1.x1.plot(ax=ax1, legend=False)

df2.x2.plot(ax=ax2, legend=False)

I get OverflowError and a very long traceback but I think the problem is how the sharex=True is handled. When I set sharex=False, the error goes away and it plots fine but unaligned.

Output of pd.show_versions()

I get ImportError: Can't determine version for pip
But:
Pandas: 1.2.3
Matplotlib: 3.3.2

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

@shaharkadmiel shaharkadmiel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 16, 2021
@mzeitlin11
Copy link
Member

Hi @shaharkadmiel, thanks for the report! I can reproduce this on current master - based on the traceback it is possible this is a matplotlib issue as well. Investigations welcome!

@mzeitlin11 mzeitlin11 added Datetime Datetime data dtype Visualization plotting and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 18, 2021
@mzeitlin11 mzeitlin11 added this to the Contributions Welcome milestone Mar 18, 2021
@shaharkadmiel
Copy link
Author

shaharkadmiel commented Mar 19, 2021

This works:

fig, (ax1, ax2) = plt.subplots(2, sharex=True)
fig.subplots_adjust(0, 0, 1, 1, hspace=0.15)


ax1.plot(df1.index, df1.x1)

ax2.plot(df2.index, df2.x2)

So I am not so sure this is a matplotlib issue.

@konnyakmannan
Copy link

konnyakmannan commented May 29, 2021

Hi, I got the same error and have investigated it.
I suppose the problem is handling sharex=True through matplotlib interface.

works properly with pandas API, like this

fig, (ax1, ax2) = plt.subplots(2, sharex=False)
fig.subplots_adjust(0, 0, 1, 1, hspace=0.15)

df1.x1.plot(ax=ax1, legend=False, sharex=True)

df2.x2.plot(ax=ax2, legend=False, sharex=True)
versions
INSTALLED VERSIONS
------------------
commit           : 2cb96529396d93b46abab7bbc73a208e708c642e
python           : 3.8.5.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.10.0-1029-oem
Version          : #30-Ubuntu SMP Fri May 28 23:53:50 UTC 2021
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : ja_JP.UTF-8
LOCALE           : ja_JP.UTF-8

pandas           : 1.2.4
numpy            : 1.20.3
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 20.2.2
setuptools       : 49.6.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.4.2
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None
>>> 

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@azjps
Copy link

azjps commented Dec 26, 2023

This is due to the same underlying issue as #52895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Visualization plotting
Projects
None yet
Development

No branches or pull requests

5 participants