How to plot a chart in the terminal

termplotlib (a small project of mine) might come in handy here. Install with

pip install termplotlib

and produce terminal plots like

import termplotlib as tpl
import numpy as np

x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x) + x
fig = tpl.figure()
fig.plot(x, y, width=60, height=20)
fig.show()
  7 +---------------------------------------------------+
    |                                                   |
  6 |                                             **    |
    |                                           **      |
    |                                         **        |
  5 |                                       **          |
    |                                     ***           |
  4 |                                  ****             |
    |                              *****                |
  3 |             *****************                     |
    |          ****                                     |
  2 |       ***                                         |
    |     ***                                           |
    |   ***                                             |
  1 |  **                                               |
    |**                                                 |
  0 +---------------------------------------------------+
    0      1       2      3       4      5       6      7

Leave a Comment