Chronology Current Month Current Thread Current Date
[Year List] [Month List (current year)] [Date Index] [Thread Index] [Thread Prev] [Thread Next] [Date Prev] [Date Next]

Re: Graph Plotting - Reprise



On Thu, 17 Aug 2000, Ludwik Kowalski wrote:

One can write your own program to save $. Here is a file
(f.dat) with data; it can be as long as desired. My program
is for a case when y are always positive; it knows that y=-1
is the end of data mark (not to be counted as data item).

I've been learning to program in Python lately. Just for fun, I thought I'd
duplicate Ludwik's example in Python to give all of you a little taste of
how it works.

Python is available from http://www.python.org/ and is completely free. It's
object-oriented and cross-platform. The syntax is quite simple and I've
really enjoyed programming with it. Someone of you might want to give it a
spin.

Here's the program:

--snip--
# stripchart.py

def get_input():
l = []
print 'Enter a list of numbers to plot (-1 to end).'
while 1:
x = input('? ')
if x <= 0:
break
else:
l.append(x)
return l

data = get_input()
maxValue = 0
for i in data:
if i > maxValue:
maxValue = i

# print graph by looping through the list
print '|---------' * 7
for i in data:
print '#' * int(round(70 * i/maxValue))
--snip--

And here's the output:

wilsont@gershwin:~/python$ python stripchart.py
Enter a list of numbers to plot (-1 to end).
? 34.5
? 67.1
? 22.9
? 44.6
? 12.0
? 10.0
? 3.7
? 38.2
? -1
|---------|---------|---------|---------|---------|---------|---------
####################################
######################################################################
########################
###############################################
#############
##########
####
########################################

Later,
Tim

--
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN | | http://slashdot.org/
wilson@visi.com | <dtml-var pithy_quote> | http://linux.com/