Speaking of graphs, matplotlib is probably the most famous, but AsciiChart draws graphs as ASCII characters directly on the console. There is a convenient library called. At first glance, I couldn't find an article that seems to be introduced in Qiita yet, so I thought it would be helpful as much as possible, so I wrote it.
pip
Install ʻasciichartpy` with the pip command.
$ pip install asciichartpy
This is the sample source used in the image at the top.
You can configure various things with the parameter cfg
, but in this example, I changed the color of series
.
import asciichartpy
from math import cos
from math import pi
import random #Postscript 2020/09/14 Thank you for pointing out
if __name__ == '__main__':
width = 120
config = {
'colors': [
asciichartpy.green,
asciichartpy.magenta,
asciichartpy.red
]
}
print(asciichartpy.plot(
series=[[random.randint(1, 15) * cos(i * ((pi * 4) / width)) for i in range(width)],
[random.randint(1, 15) * cos(i * ((pi * 2) / width)) for i in range(width)],
[random.randint(1, 15) * cos(i * ((pi * 9) / width)) for i in range(width)]],
cfg=config
)
)
I hope you find it helpful. Thank you very much.
Recommended Posts