473,909 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(reques t):
from PIL import Image as PILImage
from matplotlib.back ends.backend_ag g import FigureCanvasAgg as
FigureCanvas
from matplotlib.figu re import Figure
from StringIO import StringIO
fig = Figure()
canvas = FigureCanvas(fi g)
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_rend erer().get_canv as_width_height ()
buf=canvas.tost ring_rgb()
im=PILImage.fro mstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
imdata=StringIO ()
im.save(imdata, format='JPEG')
response = HttpResponse(im data.getvalue() , mimetype='image/jpeg')
return response

Thanks for your help!
Erik

May 30 '07 #1
0 1027

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12546
by: Brian Shade | last post by:
Hi all. I am having a bit of a problem with my Perl script and the creation of a chart. I can create the chart and create a new SeriesCollection. I then specify the XValues and the Values parameter of the first SeriesCollection object. I add another SeriesCollection, but I am only able to set the XValues and I get the following error when I try to set the Values parameter: OLE exception from "Microsoft Office Excel": Unable to set the...
8
5715
by: Prabhakar | last post by:
Friends, I have been migrating ASP applications from IIS4.0/NT4.0 to IIS5.0/W2K. All the applications working perfectly except one. This particular application will make use of asp chart object. Sub BuildGraph(rate(), name,color,chartHight,chartWidth)
22
6808
by: PeteCresswell | last post by:
I've been to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mschrt/html/vbobjtitleobject.asp, but still don't have a clue. For example, I've got a chart object namde 'grphStats' in a form named frmChart. ?Forms!frmChart!grphStats.Name returns "grphStats" as expected, but I can't get any further.
1
3180
by: Saintor | last post by:
This is for A97 in runtime or MDE mode. My intent was to define a temporary query using the recordsetclone property / filter / orderby. The controlsource of my chart would be based on a grouped query based on this temporary query. Is this the best way or is there another one more efficient? Is it possible in a runtime environment to change the format of an axis (by Week ---> by Month) or the chart controlsource on report opening?
3
12258
by: John Kotuby | last post by:
Hi all... I am trying to do a simple thing and maybe am missing something elementary. I have created a Javascript function at the top of a page which is meant to enable editing of an HTML input textbox when the user makes a selection from the DropDownList control. Since there is no OnClick event I have tried using OnSelectedIndexChanged or OnTextChanged such as OnTextChanged ="ckCat()" with ckCat being the javascript function name. I...
1
1601
by: unsichtbar | last post by:
Sorry, but I'm pretty new to .NET/XML etc... I have the current code which I'm trying to output dynamically so it can be read into a flash file. The only issue is, it doesn't seem to actually do anything. What am I missing? I have been able to output to an xml file, but not dynamically. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <%@ Import Namespace="System.Data" %> <%@ Import...
0
1601
by: sejal17 | last post by:
Hello, Every one i am trying to draw chart using web chart , its working fine in my local pc but when i am uploading this application on server i am getting Error like , System.Application.Exception : Error while rendering the chart --->system.Runtime.InteropServices.ExternalException : A generic error ouccurred in GDI+ at System.Drawing.Image.Save(String Filename,Imagecodeinfo encoder,EncoderParameters encoderparams) at...
1
3262
by: jsibrahimeye | last post by:
when i call the crystal report (using chart) from flexbuilder (in windows vista) i am getting error message on the page. CrystalReportViewer - CrystalReportViewer1 Error: Fail to render the page
1
5024
by: cubekid | last post by:
I am using OWC 11 in my new web application for displaying charts. Is it possible in OWC 11 to combine and display a column and a line graph (Looking like they overlap each other)? I tried it using this code but it doesn' t work. int width = 400; int height = 300; Bitmap bmpChart = new Bitmap(width, height, PixelFormat.Format16bppRgb555);
0
10037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11348
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11052
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9727
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7249
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6140
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.