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
FigureCanvas
    from matplotlib.figure import Figure
    from StringIO import StringIO
    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111)
    #ax.plot([1,2,3])
    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
    fracs = [15,30,45, 10]
    ax.pie(fracs, labels=labels)
    #ax.set_title('hi mom')
    ax.grid(True)
    #ax.set_xlabel('time')
    #ax.set_ylabel('volts')
    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='JPEG')
    response = HttpResponse(imdata.getvalue(), mimetype='image/jpeg')
    return response

Thanks for your help!
Erik

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