Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

Trying to render a pie chart

HI all,

I'm trying to use Matplotlib to render a pie chart for a django site
I'm working on.

I can't figure out how to get rid of the grey background, or make the
dimensions square (it's getting stretched).

Here is the code:

def oldchart(request):
    from PIL import Image as PILImage
    from matplotlib.backends.backend_agg import FigureCanvasAgg as
    from matplotlib.figure import Figure
    from StringIO import StringIO
    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111)
    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
    fracs = [15,30,45, 10]
    ax.pie(fracs, labels=labels)
    #ax.set_title('hi mom')
    size = canvas.get_renderer().get_canvas_width_height()
    im=PILImage.fromstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
    im.save(imdata, format='JPEG')
    response = HttpResponse(imdata.getvalue(), mimetype='image/jpeg')
    return response

Thanks for your help!

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc