Forgot "reply-to-all".
Eric
--- Begin Message ---
Erik Wickstrom wrote:
Hi all,
I'm trying to generate a pie chart to use in my django web app. But
it keeps rendering in a rectanuglar canvas instead of a square one, so
see inserted call to set_aspect method, below.
the pie is oblong instead of circular. It also keeps rendering with a
grey background, I need the background to be white.
see inserted call to set_facecolor method, below.
I've attached a jpg of the chart - here is my source.
Do you really want jpeg? It is suitable for photos, but very inefficient
(and a bit fuzzy) for things like pie charts. I would use png format
instead, which is efficient for this sort of plot.
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()
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, shadow=True)
ax.set_aspect('equal', adjustable='box')
fig.set_facecolor('w')
#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
Also - can I choose my own colors for the slices?
Yes, use the "colors" kwarg to specify your own list. From the docstring:
PIE(x, explode=None, labels=None,
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
autopct=None, pctdistance=0.6, shadow=False)
Eric
--- End Message ---
-------------------------------------------------------------------------
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