termplot

Published

December 1, 2022

import termplotlib as tpl
import numpy as np

x = np.linspace(0, 2 * np.pi, 10)
y = np.sin(x)
import termplotlib as tpl
import numpy as np

rng = np.random.default_rng(123)
sample = rng.standard_normal(size=1000)
counts, bin_edges = np.histogram(sample)

fig = tpl.figure()
fig.hist(counts, bin_edges, orientation="horizontal", force_ascii=False)
fig.show()
-3.30e+00 - -2.66e+00  [  8]  █▎
-2.66e+00 - -2.03e+00  [ 22]  ███▌
-2.03e+00 - -1.39e+00  [ 50]  ████████
-1.39e+00 - -7.56e-01  [123]  ███████████████████▋
-7.56e-01 - -1.20e-01  [236]  █████████████████████████████████████▊
-1.20e-01 - +5.16e-01  [250]  ████████████████████████████████████████
+5.16e-01 - +1.15e+00  [172]  ███████████████████████████▌
+1.15e+00 - +1.79e+00  [111]  █████████████████▊
+1.79e+00 - +2.42e+00  [ 22]  ███▌
+2.42e+00 - +3.06e+00  [  6]  █
import termplotlib as tpl

fig = tpl.figure()
fig.barh([3, 10, 5, 2], ["Cats", "Dogs", "Cows", "Geese"], force_ascii=True)
fig.show()
Cats   [ 3]  ************
Dogs   [10]  ****************************************
Cows   [ 5]  ********************
Geese  [ 2]  ********
import termplotlib as tpl
import numpy as np

rng = np.random.default_rng(123)
sample = rng.standard_normal(size=1000)
counts, bin_edges = np.histogram(sample, bins=40)
fig = tpl.figure()
fig.hist(counts, bin_edges, grid=[15, 25], force_ascii=False)
fig.show()
                  ▇  █
                ▁ █ ▁█ ▄
                █ █▂██▁█
                █▅██████ ▄▄
               ▃████████▃██ ▆
               █████████▉██▇█
            ▅▅▇█████████▉████▁▅
           ▂██▉█████████▉██████▃
      ▃▁ ▅▇███▉█████████▉███████
▂ ▂▄ ▄████████▉█████████▉████████▆▄▅▃▂ ▁