[Tutor] Text Scatter Plots?

R. Alan Monroe amonroe at columbus.rr.com
Wed Oct 1 15:49:23 CEST 2008


> Is there a text graphics module that does say scatter plots or
> histograms? I'm thinking of stuff prior to the graphics era of
> computing. I'm looking for something really simple.

Here's a quick and dirty way to do basic histogram of dice rolls:


import random

rolls={}

for x in range(10000):
    a = [random.randint(1,10) for x in range(2)]
    v = sum(a)
    
    try:
        rolls[v] += 1
    except KeyError:
        rolls[v] = 1

m = max(rolls.values())
stretch = (m/70.0)

for x in rolls.keys():
    print x, rolls[x], '*' * ( int(rolls[x] / stretch)  )



More information about the Tutor mailing list