Hi,

I'm trying to plot a barchart for use in a django site.  It's creating
a blank chart image though.(attached).

What am I doing wrong?

from pylab import *
def chart(request):
   from PIL import Image as PILImage
   from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
   from matplotlib.figure import Figure
   from StringIO import StringIO
   fig = Figure(figsize=(6,4))
   canvas = FigureCanvas(fig)
   ax = fig.add_subplot(111)
   #from pylab import *
   N = 7
   menMeans = (20, 35, 30, 35, 27, 21, 60)
   ind = arange(N)  # the x locations for the groups
   #print ind
   width = 0.35       # the width of the bars
   ax = bar(ind, menMeans, width, color='b')
   #ylabel('Time')
   title('Time In Minutes - Last 7 Days')
   xticks(ind+width, ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', '*') )
   fig.set_facecolor('w')
   canvas.draw()
   size = canvas.get_renderer().get_canvas_width_height()
   buf=canvas.tostring_rgb()
   im=PILImage.fromstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
   imdata=StringIO()
   im.save(imdata, format='PNG')
   response = HttpResponse(imdata.getvalue(), mimetype='image/png')
   return response


Thanks!
Erik

<<attachment: chart.png>>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to