472,118 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 software developers and data experts.

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!

May 30 '07 #1
0 957

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brian Shade | last post: by
8 posts views Thread by Prabhakar | last post: by
22 posts views Thread by PeteCresswell | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.