termplot is a little gem library, it plots two types of graphs:

  1. line plot — Y (value) against X (time), and
  2. histogram.

Here is an example code for sin(2πx)+sin(52πx).


import math
from termplot import Plot, LINE, HISTOGRAM

POINTS = 1000
xvals, yvals = [], []
for i in range(0, POINTS):
x = i * 2 * math.pi / POINTS
xvals.append(x)
yvals.append(math.sin(x) + math.sin(x * 5))

Plot(xvals, yvals, LINE)
Plot(yvals, plot_type=HISTOGRAM)

The plots:


2.0| **
|
1.555555| * *
| * *
1.111111| * * * * * *
| *
0.666666| * * *
| * *
0.222222| * * * *
|* * * * * * * * * *
-0.22222| * * * *
| * *
-0.66666| * * *
| *
-1.11111| * * * * * *
| * *
-1.55555| * *
|
-2.0| **
||‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
0.0 1.7435839227 3.4871678454 6.27690212187


58.0| * *
| . .
52.0| . .
| * . . *
46.0| . . . .
| . .* *. .
40.0| . .. .. .
| . .. *.. .
34.0| . ..*... .
| . ...... .
28.0| . ...... .
|* .* ...... *.
22.0|. ..* ...... *..
|. ...** * ...... * **...
16.0|. .....*** * . *......* . * ***..... *
|. ........**.*.*........*.*.**........ .
10.0|.* .................................... *.
|..***** *....................................* *****..
4.0|.......*......................................*.......
||‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
-2.0 -0.888888888 0.2222222222 2.0

Bucketwidth = 0.0740740740741

I like the gauassian distribution too much, so here it is — by the example code in README:


6882.0| ***
| *...
6117.333| *....*
| *......*
5352.666| ........
| *........*
4588.0| *..........*
| ............
3823.333| *............*
| ..............
3058.666| ..............*
| *...............
2294.0| *................*
| *..................*
1529.333| ....................
| **....................**
764.6666| *........................*
| **..........................***
0.0|***********...............................************
||‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
-6.789193021 -2.880781838 1.0276293444 7.28108723686

Bucketwidth = 0.260560745519

The axes are drawn perfectly, and I particularly like the fill-character . below the * in the histogram.

Although it’s a library, the code can actually get data from a file, however, that part of code doesn’t seem finished, it can only accept one-column of data, and X is numbered by the line numbers.

One year ago, hipsterplot uses 123 lines with very good ASCII draying, this library is 169 lines, a bit longer, but with histogram plotting.

termplot was created by Brendan Cod on 2014-07-18, in Python 2, under the MIT License.