6 Oct 02:46
Axes.add_line() is oddly slow?
From: Eric Firing <efiring@...>
Subject: Axes.add_line() is oddly slow?
Newsgroups: gmane.comp.python.matplotlib.devel
Date: 2008-10-06 00:50:26 GMT
Subject: Axes.add_line() is oddly slow?
Newsgroups: gmane.comp.python.matplotlib.devel
Date: 2008-10-06 00:50:26 GMT
I am getting very inconsistent timings when looking into plotting a line
with a very large number of points. Axes.add_line() is very slow, and
the time is taken by Axes._update_line_limits(). But when I simply run
the latter, on a Line2D of the same dimensions, it can be fast.
import matplotlib
matplotlib.use('template')
import numpy as np
import matplotlib.lines as mlines
import matplotlib.pyplot as plt
ax = plt.gca()
LL = mlines.Line2D(np.arange(1.5e6), np.sin(np.arange(1.5e6)))
from time import time
t = time(); ax.add_line(LL); time()-t
###16.621543884277344
LL = mlines.Line2D(np.arange(1.5e6), np.sin(np.arange(1.5e6)))
t = time(); ax.add_line(LL); time()-t
###16.579419136047363
## We added two identical lines, each took 16 seconds.
LL = mlines.Line2D(np.arange(1.5e6), np.sin(np.arange(1.5e6)))
t = time(); ax._update_line_limits(LL); time()-t
###0.1733548641204834
## But when we made another identical line, updating the limits was
## fast.
# Below are similar experiments:
LL = mlines.Line2D(np.arange(1.5e6), 2*np.sin(np.arange(1.5e6)))
t = time(); ax._update_line_limits(LL); time()-t
###0.18362092971801758
(Continue reading)
RSS Feed