plot() in a loop vs multiple curves with a single plot()

A B <python6009@...287...> writes:

I have the following code and am wondering whether there is a more
efficient way to plot multiple curves. Maybe somehow accumulating the
data into a single variable, then calling plot once ... Thanks for any
ideas.

for ofile in files:
    d = mlab.csv2rec(ofile, names = ['date','field'])
    ax.plot(d['date'], d['field'])

You can give multiple x,y pairs to plot, so perhaps something like

data = [mlab.csv2rec(f, names=['date','field']) for f in files]
data = [[x['date'],x['field']] for x in data]
ax.plot(*np.concatenate(data))

would work. But I don't know if it's really any more efficient. For
large plots, you may want to take a look at collections:

http://matplotlib.sourceforge.net/api/collections_api.html#matplotlib.collections.LineCollection

···

--
Jouni K. Sepp�nen