Skip to content

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

@cinsk

Description

@cinsk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssue that has not been reviewed by a pandas team memberPerformanceMemory or execution speed performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions