Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The plot function of the matplotlib 2 and 3 versions is much slower than 1.5.3 #12542

Closed
@materia9

Description

@materia9

Bug report

Bug summary

The plot function of the matplotlib 2 and 3 versions is much slower than the plot function of matplotlib 1.5.3 if one plots many lines (and other objects) in an Axes.

Code for reproduction

I have tested it on an Ubuntu server (CLI only), version 16.04 with python 3.5.2 (through virtualenv), matplotlib 1.5.3 with backend agg set by matplotlibrc.

setup="""import matplotlib.pyplot as plt
a=[1,2]"""
test="plt.plot(a,a,'-')"
import timeit
timeit.timeit(test,setup,number=1000)
# output: 0.6324263589922339
timeit.timeit(test,setup,number=1000)
# output: 0.6100882450118661
timeit.timeit(test,setup,number=1000)
# output: 0.6113728249911219

=> around 0.6-0.7 sec, it is stable for a few dozen times.

On the same machine & operating system, python 3.5.2 (through virtualenv), matplotlib 2.2.2 with backend agg.

setup="""import matplotlib.pyplot as plt
a=[1,2]"""
test="plt.plot(a,a,'-')"
import timeit
timeit.timeit(test,setup,number=1000)
# output: 0.9981246230890974
timeit.timeit(test,setup,number=1000)
# output: 1.3041282850317657
timeit.timeit(test,setup,number=1000)
# output: 1.6257964670658112
timeit.timeit(test,setup,number=1000)
# output: 1.9830634299432859

=> getting slower and slower...

Note that matplotlib 2.0.0, 2.0.1, 2.1.0, 2.1.2, 2.2.2, or 3.0.0 has the same slowdown behavior. If I set svg as backend, the result is the same as agg (I confirmed backend="svg" only for matplotlib 2.0.0 on the Ubuntu server).

This behavior is also confirmed on a Windows distribution: WinPython-64bit-3.4.4.6Qt5 with matplotlib 2.0.0 and default backend TkAgg, but not for WinPython-64bit-3.4.4.5Qt5 with matplotlib version 1.5.3 and TkAgg, though the situation is much more complex. In addition, WinPython-64bit-3.5.1.1 and matplotlib 2.1.0 (packaged by Christoph Gohlke) causes the same slowdown behavior.

Another windows distribution anaconda 3 version 4.4.0(64bit) also has a similar behavior. For the anaconda 3 environment, all the packages are default of the 4.4.0 distribution (python 3.6 and matplotlib 2.0.2 with backend qt5agg), and it runs on windows7-x64.

If I close the figure by pyplot.close(), the slowed plot() is returned to the initial state.

Expected outcome

The expected outcome is "no slowdown for the plot function of matplotlib 3" as the matplotlib version 1.5.3.

Matplotlib version

  • Operating system: Ubuntu 1604 (CLI only)
  • Matplotlib version: matplotlib 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.5.2
  • Jupyter version (if applicable):
  • Other libraries:

Other note

I have used a script to write huge maps with overlayed many lines drawn by plot(). When I'm with matplotlib 1.5.3, it takes several minutes to output a bunch of png files, but no fatal problem is there. However, with 2.0.0-3.0.0 it takes several hours or more, and I cannot use the script at all.

I believe this slowdown behavior can occur for most of the matplotlib environments. I think this is not an OS/system dependent bug/specification.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions