Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Bug summary
For relatively simple plotting examples theplt.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 time
Code for reproduction
importnumpyasnpimporttimeimportmatplotlibimportmatplotlib.pyplotaspltprint(matplotlib.__version__)defprofile_expression(expression):importcProfileimporttempfileimportosimportsubprocesstmpdir=tempfile.mkdtemp()statsfile=os.path.join(tmpdir,"profile_expression_stats")print("profile_expression: running")t0=time.perf_counter()cProfile.run(expression,statsfile)dt=time.perf_counter()-t0print(f"profiling:{dt:.2f} [s]")r=subprocess.Popen(["snakeviz",statsfile])returnrx=np.linspace(0,10,1000)y=np.linspace(0,20,1000)**0.1defgo():foriiinrange(5):plt.figure(100);plt.clf()plt.plot(x,y,'.',label='n')plt.plot(x,y+x,'.-',label='m')plt.xlabel('dsf')plt.title('sdfs')plt.legend()plt.draw()if__name__=='__main__':profile_expression('go()')
Actual outcome
The output of the minimal example (which requireshttps://github.com/jiffyclub/snakeviz to be installed) is a profiling graph of the code executed in the minimal example:
Expected outcome
Theplt.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