-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: matplotlib.pyplot.clf is very slow #23771
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
Comments
Tick handling is a known performance issue, but it's hard to change due to compatibility (see #5665 for a general discussion). We already have some optimizations, but they may not apply to
Edit: The clearing issue is also described/addressed in #16067 |
I'm also a bit surprised how much time we are spending in the deprecation machinery.... |
The overhead of the deprecation is really low. The reported times in the profiling graph are cummulative which is why they show up. What you see is just this:
|
Creating new figures (e.g. |
The method
to Example output for script
is
|
To be checked: Why do we clear the Axes before deleting them? matplotlib/lib/matplotlib/figure.py Line 987 in 5461ae2
|
My off-the-cuff guess is that we are doing that to help the garbage collector out and break some of the reference cycles. |
Ok, then we could possibly write some more lightweight |
Bug summary
For relatively simple plotting examples the
plt.clf()
command can take over 30% of the calculation time. One would expect that a clear command is relatively simple and takes a limited amount of timeCode for reproduction
Actual outcome
The output of the minimal example (which requires https://github.com/jiffyclub/snakeviz to be installed) is a profiling graph of the code executed in the minimal example:
Expected outcome
The
plt.clf()
should be very fast compared to the actual plotting. Going into the details of the profiling results shows a large amount of time being spend inaxis.reset_ticks
.Additional information
No response
Operating system
Windows
Matplotlib Version
3.6.0.dev3058+g87197156eb
Matplotlib Backend
Qt5Agg
Python version
3.10.0
Jupyter version
No response
Installation
git checkout
The text was updated successfully, but these errors were encountered: