Chart plotting blank?

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

chart.png

You have commented out the line 'from pylab import *' which is the
right thing for a web app server. But then you wrote

ax = bar(ind, menMeans, width, color='b')

which should raise a NameError because bar is defined in the pylab
namespace. So it looks like somewhere in your code which you are not
showing to us you have imported from pylab, which is wrong. What you
want to do is

ax = fig.add_subplot(111)
ax.bar(ind, menMeans, width, color='b')

and after that, read the user's guide, tutorial,
the FAQ http://matplotlib.sourceforge.net/faq.html#OO, and the API
tutorial http://matplotlib.sourceforge.net/leftwich_tut.txt <wink>

JDH

···

On 6/5/07, Erik Wickstrom <erik@...1629...> wrote:

    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')