473,657 Members | 2,896 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 1011

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

Similar topics

1
12519
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
5692
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
6773
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
3167
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
12246
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
1588
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
1588
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
3242
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
5003
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
8384
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
8820
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
8718
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...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.