Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: matplotlib.pyplot.clf is very slow #23771

Open
@eendebakpt

Description

@eendebakpt

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:

image

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp