Issue
I use to do a lot of datascience post-processing with python and matplotlib and thanks everyday Guido and the community for their work.
But recently I felt in a strange situation : one of my scripts works "well" on a computer, but is terribly slow on another one... which is supposed to use the same configuration (same Ubu22.04 master which encloses the same python version).
I ended to isolate what seems to be my problem, it occurs when I ask matplotlib to create the figure (plt.subplots in my case), when it's done the plots are normally fast. Here is my testing program:
import sys
print(f'python v{sys.version}')
import time
start = time.time()
import matplotlib
import matplotlib.pyplot as plt
v = matplotlib._version.version
end = time.time()
print(f'matplotlib.v{v} imported in {end-start:.1f} sec')
print(f' (from {matplotlib.__file__})')
start = time.time()
backend = matplotlib.rcParams["backend"]
end = time.time()
print(f'backend {backend} identified in {end-start:.1f} sec')
start = time.time()
fig, ax = plt.subplots()
end = time.time()
print(f'plt.subplots called in {end-start:.1f} sec')
plt.show()
and what I get on my two computers :
PC1 :
python v3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
matplotlib.v3.6.2 imported in 0.4 sec
(from /volatile/home/XXXX/.local/lib/python3.10/site-packages/matplotlib/__init__.py)
backend GTK4Agg identified in 2.4 sec
plt.subplots called in 0.8 sec
PC2 :
python v3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
matplotlib.v3.6.3 imported in 0.4 sec
(from /volatile/home/XXXX/.local/lib/python3.10/site-packages/matplotlib/__init__.py)
backend GTK4Agg identified in 2.2 sec
plt.subplots called in 25.9 sec
I read many other such posts but couldn't find anyone which really relates to my situation (it's not the plot which is slow but the creation of the figure).
I tried to change the backend but have no other one.
I tried to change my matplotlib version, but it doesn't have any influence on the result. I also checked other modules versions (pandas, numpy) without success.
Does anyone have an idea of where should I dig to fix this?
Solution
In enventually found the origin of this problem, it was related to the backend. I could install PyQt5 which solved perfectly the slowness of my scripts.
Answered By - FredJ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.