To create a new plot, I usually execute the plotting-script repeatedly using execfile('plot.py') in ipython. When the plot contains a large amount of data or some non trivial preprocessing this can take sometimes an inconveniant amount of time, as the calculations are redone and the data is reloaded even if only e.g. the axis labels are changed. To speed up the turnaround I developed a lazy data cache.

Here, the workload is moved to a function which is given to the cache object and only executed once even on consecutive calls of execfile. Parameters as e.g. filenames or similar can be passed to the function, e.g.

def foo(v):
  print 'foo'
	return ones(100) * v

dataCache['a'] = foo,[42]

plot(dataCache['a'])

will plot a line with y-value 42, but in consecutive executions `foo’ will be printed only one time.

The datacache is implemented in the matplotlibtools package. In the implementation, the cache object can also be saved to file for a quick and dirty serialization of intermediate plots.