Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 22nd, 2005, 2:37 PM   #1
sojo
Newbie
 
Join Date: Jun 2005
Location: Indianapolis
Posts: 2
Rep Power: 0 sojo is on a distinguished road
Unhappy Need help with rounding numbers[SOLVED]

I know....i know.....sounds stupid...but just look and see if anyone can give me a hand.

I am creating a script that needs to display numbers at the top of a graph. The problem is...the numbers are out to around 9 decimal places...I need them at 1. I have tried the round command, but it doesnt work.

The following is the code...the bold areas being the problem areas.
(and yes...'E'...is a list of numbers.--->E=[.......])

Python will not let me round E...giving me the error message---> typeerror: a float is required. If anyone can help...you have my thanks.

(The {value} input refers to the data= section of code)
-------------------------------------------------------------
def sort_by_value(d):
    """ Returns the keys of dictionary d sorted by their values """
    items=d.items()
    backitems=[ [v[1],v[0]] for v in items]
    backitems.sort()
    return [ backitems[i][1] for i in range(0,len(backitems))]

SBV=sort_by_value

A=SBV(E)

B=sorted(E.values())

#!/usr/bin/python
from pychartdir import *

#The data for the bar chart
data = B

#The labels for the bar chart
labels = ["BMS","ST","FG","CV","LN","CMS","LC","BP","MEC","ABE","HH","IC","MCC","OE","SS","FCV","WR"]

#The colors for the bar chart
colors=[0x000099,0x003300,0x003300,0x003300,0x990000,0x000099,0x990000,0x003300,0x003300,0x003300,0x003300,0x003300,0x990000,0x003300,0x003300,0x000099,0x003300]

#Create a XYChart object of size 260 x 220 pixels. Use golden background color.
#Use a 2 pixel 3D border.
c = XYChart(780, 660, goldColor(), -1, 2)

#Add a title box using 10 point Arial Bold font. Set the background color to
#metallic blue (9999FF) Use a 1 pixel 3D border.
c.addTitle("Educational Adequacy", "arialbd.ttf", 10).setBackground(metalColor(
    0x9999ff), -1, 1)

#Set the plotarea at (40, 40) and of 200 x 150 pixels in size
c.setPlotArea(120, 120, 600, 450)

#Add a multi-color bar chart layer using the given data and colors. Use a 1
#pixel 3D border for the bars.

#Set the labels on the x axis.
c.xAxis().setLabels(labels)

layer = c.addBarLayer(data, c.gradientColor(120, 0, 717, 0, 0xff0000, 0x0000ff))

#Set the bar gap to 10%
layer.setBarGap(0.1)

#Use the format " xxx " as the bar label
layer.setAggregateLabelFormat("{value}")

#Set the bar label font to 10 pts Times Bold Italic/dark red (0x663300)
layer.setAggregateLabelStyle("timesbi.ttf", 10, 0x663300)

#output the chart
c.makeChart("Ecompare.jpg")
--------------------------------------------------------------------

Last edited by sojo; Jun 23rd, 2005 at 10:48 AM. Reason: problem solved
sojo is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:45 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC