Skip to content

PERF: 100% CPU utilization with matplotlib (macosx) #58963

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

Closed
2 of 3 tasks
cinsk opened this issue Jun 9, 2024 · 1 comment
Closed
2 of 3 tasks

PERF: 100% CPU utilization with matplotlib (macosx) #58963

cinsk opened this issue Jun 9, 2024 · 1 comment
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance

Comments

@cinsk
Copy link

cinsk commented Jun 9, 2024

Pandas version checks

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

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

  • I have confirmed this issue exists on the main branch of pandas.

Reproducible Example

machine: Mac (Intel) Ventura 13.6.6
python version: 3.12.3 (pyenv)
pandas version: 2.2.2 (pip)
matplotlib version: 3.9.0 (pip) (backend: macosx)

Problem: With matplotlib, pandas consumes 100% CPU.

Below code runs with reasonable CPU utilization; when the canvas was shown, almost no cpu utilization.

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(range(5))
plt.show()

After closing the matplotlib window, simply importing pandas drives the CPU utilization 100%.

import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot(range(5))
plt.show()
# after closing the window
import pandas              # starting 100% CPU utilization

If I start the python interpreter, and running following code also consumes 100% of CPU:

import matplotlib.pyplot as plt
import pandas as pd

# No CPU utilization at the moment

fig = plt.figure()
df = pd.DataFrame(range(5))

plt.plot(df[0])           # with this, CPU utilization is 100%.
plt.show()                 # the same

# after closing the window, still 100%

The closest hint that I found was this: matplotlib/matplotlib#4092

I'm not sure but, I suspect that pandas' GUI backend initialization code (if any) for matplotlib (macosx backend) somehow creating this problem?

Without pandas, matplotlib's plot() alone does not cause high CPU utilization, so I post this here.

Installed Versions

INSTALLED VERSIONS ------------------ commit : d9cdd2e python : 3.12.3.final.0 python-bits : 64 OS : Darwin OS-release : 22.6.0 Version : Darwin Kernel Version 22.6.0: Mon Feb 19 19:48:53 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : None
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.9.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

Prior Performance

No response

@cinsk cinsk added Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance labels Jun 9, 2024
@cinsk cinsk changed the title PERF: PERF: 100% CPU utilization with matplotlib (macosx) Jun 9, 2024
@cinsk
Copy link
Author

cinsk commented Oct 9, 2024

After I switched the backend of matplotlib from macosx to qt5agg, the problem was gone. It's likely the matploblib backend issue, not pandas.

closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance
Projects
None yet
Development

No branches or pull requests

1 participant