Some comments inline:
Beware of the glaring security problem there, you are eval()ing input
controlled by the remote user.
> subplot(1,2,1), plot(x, sin(alpha*x), '.-')
> subplot(1,2,2), plot(x,sin(alpha*x*cos(alpha*x)), 'o-')
> savefig("sin.png", dpi=96)
You might want to think about concurrency here, unless there is only
one user. Reusing the same filename sin.png could lead to problems
where one user's request to visu happens between another one's
requests to visu and showimage, effectively overwriting sin.png before
the latter can retreive his.
One idea is to use the tempfile module to generate a unique temporary filename:
http://docs.python.org/lib/module-tempfile.html
Perhaps a better idea, is to output the image data directly to the
response, without saving it to disk. Judging by
http://matplotlib.sourceforge.net/matplotlib.pyplot.html#-savefig
savefig can accept a file-like object instead of a filename. In this
case, you would move the code that generates the plot to showimage,
and call savefig with a StringIO instance as the first parameter, and
return its value directly.
buf = StringIO()
savefig(buf, dpi=96, format='png')
return buf.getvalue()
> cherrypy.response.headers['Content-Type']= 'text/html'
> page = [_header]
> page.append('<img src="/showimage/" width="800" height="400" />' )
> page.append(_footer)
> return page
>
> if __name__ == '__main__':
> cherrypy.quickstart(Root())
cheers,
Arnar