Hi Timmie I m using matplotlib and instead of show() just use savefig ('filepath', dpi=dpi) I make filepath inside static dir, something like /static/myfiles/ tmp0123 This of course requires periodic cleaning by some cron script, e.g. delete all files older than 4 days. Or try to use python's tmp files lib.
Thus your controller method could look like import tempfile def get_plot(): x=arange(0, 100, 0.1) y = sin(x) plot(x, y) file, filepath = tempfile.mkstemp('.png', dir='static/myfiles/') #check that - path to static should be more explicit savefig(tmpfilepath, dpi=72) response.headers['Content-Type'] = 'application/png' #check that - I do not remember correct mime type for PNG response.headers['Content-Length'] = 10**6 return response.stream(filepath) On Apr 29, 12:30 pm, Timmie <timmichel...@gmx-topmail.de> wrote: > Hello, > I would like to create images on the fly using PIL or matplotlib. > > How can I embedd the image in a webpage? > > Normally, I would save such images to file. > > Has anyone done such things? > > Thanks in advance, > Timmie > > ### example code for image generation: > > from matplotlib.pyplot import figure, show > from matplotlib.figure import Figure > > class MyFigure(Figure): > def __init__(self, *args, **kwargs): > """ > custom kwarg figtitle is a figure title > """ > figtitle = kwargs.pop('figtitle', 'hi mom') > Figure.__init__(self, *args, **kwargs) > self.text(0.5, 0.95, figtitle, ha='center') > > fig = figure(FigureClass=MyFigure, figtitle='my title') > ax = fig.add_subplot(111) > ax.plot([1,2,3]) > > show() > > http://matplotlib.sourceforge.net/examples/pylab_examples/custom_figu... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---