[SciPy-user] Why is SciPy better than Matlab or IDL? ;)

David Warde-Farley dwf at cs.toronto.edu
Wed Jul 8 15:35:36 EDT 2009


On 8-Jul-09, at 7:48 AM, Tim Michelsen wrote:

> Would be nice to see your implementation.

The way I did it was to do the plotting onto a FigureCanvasAgg and  
then printing it to a fake file using cStringIO.

from matplotlib.backends.backend_agg import FigureCanvasAgg
import matplotlib.pyplot as plt
import cStringIO

def plot(...):
	fig = plt.figure(...) # figure out size and such here
	canvas = FigureCanvasAgg(fig)
	fig.set_canvas(canvas) # I forget whether this is needed
	# Do some plotting commands here
	...
	...
	canvas.draw()
	imgdata = cStringIO.StringIO()
	canvas.print_png(imgdata)
	return imgdata.get_value()


There's something very similar in the Matplotlib cookbook or the  
TurboGears cookbook, but I forget which.

David



More information about the SciPy-User mailing list