In web2py+matplotlib:
def simple():
import random, cStringIO
from matplotlib.backends.backend_agg import FigureCanvasAgg as
FigureCanvas
from matplotlib.figure import Figure
from matplotlib.dates import DateFormatter
fig=Figure()
ax=fig.add_subplot(111)
x=[]
y=[]
now=datetime.datetime.now()
delta=datetime.timedelta(days=1)
for i in range(10):
x.append(now)
now+=delta
y.append(random.randint(0, 1000))
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas=FigureCanvas(fig)
response.header['content-type']='image/png'
stream=cStringIO.StringIO()
canvas.print_png(stream)
return stream.getvalue()
Massimo
On Dec 16, 6:12 am, aus <[email protected]> wrote:
> Hi Massimo,
>
> thank you for your reply. Your suggestion does not seem to work, but
> maybe I'm not using Dojo properly. How would you code the plot with
> flot?
>
> Also, it would be great to be able to embed images/charts generated by
> matplotlib, similarly to what can be done with
> django:http://www.scipy.org/Cookbook/Matplotlib/Django. Is there a similar
> feature in web2py?
>
> Thank you!
>
> Cheers,
> aus
>
> On Dec 16, 6:57 am, mdipierro <[email protected]> wrote:
>
> > I do not know about Dojo. I have been using flot instead. perhaps this
> > helps
>
> > {{import gluon.contrib.simplejson as sj}}
> > {{=sj.dumps(data)}}
>
> > data will be printed in the page in json format. If your view/template
> > includes javascript code you can put the above statements in the js
> > itself.
>
> > Perhaps other users can help more.
>
> > Massimo
>
> > On Dec 15, 11:31 pm, aus <[email protected]> wrote:
>
> > > Hi everybody,
>
> > > although I have some experience with programming, javascript/AJAX is
> > > completely new to me. I'm very happy with web2py and I'm trying now to
> > > pass arrays and possibly more structured data to Dojox to plot series
> > > computed in python using Dojox's charts. How can I do that? I somehow
> > > cannot cross the wall between the templace code and the javascript
> > > code... Is JSON a possible solution? Could someone provide an example?
>
> > > thank you!
>
> > > Cheers,
> > > aus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---