hipsterplot is a Python library for plotting 2-D line chart using ASCII characters only. The following example code would plot a 2 cycles of sine wave, modified from its source code:
import math
from hipsterplot import plot
ys = [math.sin(2*math.pi*x*2/50.0) for x in xrange(100)]
num_x_chars = min(50, len(ys))
plot(ys, num_x_chars=num_x_chars, num_y_chars=15)
xs = [50*random.random() for x in xrange(100)]
ys = [math.sin(2*math.pi*x*2/50.0) for x in xs]
num_x_chars = min(50, len(ys))
plot(ys, x_vals=xs, num_x_chars=num_x_chars, num_y_chars=15)
k = 20
ys = [random.gauss(0, 0.5) + math.sin(2*math.pi*x*2/50.0/k) \
for x in xrange(50*k)]
num_x_chars = min(50, len(ys))
plot(ys, num_x_chars=num_x_chars, num_y_chars=25)
The plotted charts in ASCII:
0.9315 .... ....
0.7984 . . . .
0.6654 . .
0.5323 . . . .
0.3992 . .
0.2661 . .
0.1331 . .
-0.0000 . .
-0.1331 . .
-0.2661 . .
-0.3992 . .
-0.5323 . . . .
-0.6654 . .
-0.7984 . . . .
-0.9315 .... ....
0.9333 .||. || :
0.8000 : . #
0.6667 | . . :
0.5334 | . .
0.4001 . . |
0.2667 : | . :
0.1334 . .
0.0001 . . .
-0.1332 . | . .
-0.2665 . . . :
-0.3999 .
-0.5332
-0.6665 . : : .
-0.7998 | | |
-0.9331 |.| ::.:
2.2507 . .
2.0606 . ..
1.8706 : . .
1.6805 : .| .: .:.. ..
1.4904 ..:.: : . ::.: |.
1.3003 .::||.|:: .. |:#::
1.1102 ..:|| ||:| . ::|:|:|#.
0.9201 . .:|.##:::::.. ...::|.||. ..
0.7300 . ::.|:.###|. :.|#:|:|.#|:::
0.5400 :#|#|:.:::||. ..||#::::..||::
0.3499 ||:|: : : .:# .. |: |.||. .|.|#. |. . .
0.1598 |#|. : : |:||:. . |||||:..:.| ..:|:: . .. :
-0.0303 :.. . ...||..:.. . .::.:.|: . :. ..#.::. .
-0.2204 |.. . .:.:|||:. |..:. :| .|..|.||.. .|.
-0.4105 :: . #... :: :|..:...: | #||.:|#:|..
-0.6006 .: .. .#.|..|::| . :. |::#:..:.|
-0.7906 : :|:|||:.|:|::| :#|:..:||#|
-0.9807 .:##|#||#||: . |:::|.|:.
-1.1708 ..:|.||:# . . :.|:|.||
-1.3609 . ::.:...: : . :.::|: :
-1.5510 ||.| .: .:.
-1.7411 . . . . .... .
-1.9312 .. . . . .
-2.1213 .
-2.3113 .
It’s a very simple library, only 123 lines, including license text and the example code. Only one plotting function, that is plot.
This library isn’t alone in ASCII kingdom, not long ago, I found a library called DRAWILLE and it can even render xkcd comics using Braille.
hipsterplot is written by Ian Horn, licensed under the MIT License, for both Python 2 and 3 with separate scripts.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.