# >Asciigraph

Last Edit: Dec. 21, 2010, 9:52 p.m.

I was playing around today, and I made a little python script that can graph functions in the terminal. It could be nicer, but I'm happy enough with it. Here's some sample output:

It can graph functions from 0 to any number (you'd want a limit so it doesn't wrap). This is a graph of sin(x)

```compare.functiontogrid(function=lambda x:math.sin(x),maxx=6,scale=10,marks=15)

+1.0|
+0.9|            XXXXXXXXX
+0.8|          XX         XX
+0.7|        XX             X
+0.6|       X                X
+0.5|      X                  XX                                          X
+0.4|     X                     X                                       XX
+0.3|    X                       X                                     X
+0.2|   X                         X                                   X
+0.1|  X                           X                                 X
+0.0|XX-----------------------------XX-----------------------------XX-------
-0.1|                                 X                           X
-0.2|                                  X                         X
-0.3|                                   X                       X
-0.4|                                    X                     X
-0.5|                                     X                   X
-0.6|                                      XX                X
-0.7|                                        X             XX
-0.8|                                         XX         XX
-0.9|                                           XXXXXXXXX
-1.0|
|   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
| 0.4 0.8 1.2 1.6 2.0 2.4 2.8 3.2 3.6 4.0 4.4 4.8 5.2 5.6 6.0 6.4 6.8

```

It can do a comparison bar-graph to visually compare numbers. It has three modes, and can handle negative numbers.

```lst = ["one","two","longest","short"]
val = [-1,5,-3,4]
compare.doitall(lst,val)

longest:-0.23%:                         #######                               :
one  :-0.08%:                              ##                               :
short :+0.31%:                                ########                       :
two  :+0.38%:                                ###########                    :

val = [1,2,3,4]
compare.doitall(lst,val)

one  :0.10%:######                                                          :
two  :0.20%:############                                                    :
longest:0.30%:###################                                             :
short :0.40%:#########################                                       :

```

The last thing it can do is graph scatter plots

```nums = range(20) + range(20) + range(20)
x = random.sample(nums,50)
y = random.sample(nums,50)

out = compare.coordstogrid(x,y,marks=6)

+19.0|
+18.0|    X X
+17.0|   X         X
+16.0|  X    X     X
+15.0|       XX      X
+14.0|X           X
+13.0| X    X
+12.0|              X X
+11.0|   X X
+10.0|          X X     X
+9.0|     X   X      X
+8.0|   X             X
+7.0|  X     X
+6.0|
+5.0|    XX
+4.0| X  X  X
+3.0|          X   X
+2.0|        X X       X
+1.0|           X     X
+0.0|X-------------X-----
|  |  |  |  |  |  |
|  3  6  9 12 15 18

```

Here are the files. Compare.py is the actual file, example.py has some examples.