moneylobster / cl-text-plot

Plot with text in Common Lisp
8 stars 0 forks source link

cl-text-plot

A plotting library for Common Lisp that prints plots on the REPL using Unicode braille characters. Code quality/style may not be the best.

Can be loaded as "textplot" with ASDF/Quicklisp (as a local project)

Usage

For some reason the plots don't show up nicely on Github's markdown renderer, so the outputs look wonkier than they actually are.

Normal Plotting

(plot '((1 2) (2 6) (3 4)) :title "Cool plot")
=>

          Cool plot
6⡏⠉⠉⠉⠉⠉⠉⠉⠉⣹⠛⢍⠉⠉⠉⠉⠉⠉⠉⢹
 ⡇⠀⠀⠀⠀⠀⠀⠀ ⣰⠃⠀ ⠀⠑⢄ ⠀⠀⠀⠀⠀⢸
 ⡇⠀⠀⠀⠀⠀⠀ ⣰⠃⠀⠀  ⠀⠀⠀⠑⢄⠀⠀⠀⢸
 ⡇⠀⠀⠀⠀⠀ ⣰⠃⠀⠀⠀  ⠀⠀⠀⠀⠀⠑⢄⠀⢸
 ⡇⠀⠀⠀⠀ ⣰⠃⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀⠑⢼
 ⡇⠀⠀⠀ ⣰⠃⠀⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀⠀⢸
 ⡇⠀⠀ ⣰⠃⠀⠀⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀⠀⢸
 ⡇⠀ ⣰⠃⠀⠀⠀⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀⠀⢸
 ⡇ ⣰⠃⠀⠀⠀⠀⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀⠀⢸
2⣷⣃⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
 1                          3

Plotting Functions

(plot-fun #'sin -4 4 0.1)
=>
               0.99957365⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢉⠏⠙⢏⠉⠉⠉⢹
                         ⣇⠀⠀⠀ ⠀⠀⠀⠀⠀ ⠀⠀⠀⡎  ⠀⠘⡆⠀⠀⢸
                         ⡟⡄⠀⠀ ⠀⠀⠀⠀⠀ ⠀⠀⡸⠀  ⠀⠀⢹⠀⠀⢸
                         ⡇⢳⠀⠀ ⠀⠀⠀⠀⠀⠀⢀⠇  ⠀⠀⠀⠀⠀⡇⠀⢸
                         ⡇⠈⡆⠀ ⠀⠀⠀⠀⠀⠀⡼⠀  ⠀⠀⠀⠀⠀⢸⠀⢸
#<FUNCTION SIN>          ⡇⠀⢱⠀⠀ ⠀⠀⠀⠀⢠⠇⠀  ⠀⠀⠀⠀⠀⠀⡇⢸
                         ⡇⠀⠈⡆⠀ ⠀⠀⠀⠀⡜⠀ ⠀ ⠀⠀⠀⠀⠀⠀⢸⣸
                         ⡇⠀⠀⢱⠀⠀ ⠀⠀⢠⠃ ⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢿
                         ⡇⠀⠀⠈⣇⠀ ⠀⠀⡎⠀ ⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢸
               -0.9995735⣇⣀⣀⣀⣘⣄⣀⣜⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
                         -4.0               3.9999971
                                      x

Scatter Plots

(scatter '((1 2) (2 6) (3 3) (4 4)))
=>
6.5⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹
   ⡇⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⢸
   ⡇⠀⠀⠀⠀⠀⠀⠈⠋⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⢸
   ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀ ⠀⢸
   ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⠀⠀⠀⡀⠀⠀⢸
   ⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⠀⠀⠈⠋⠀⠀⢸
   ⡇⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⠠⡦⠀⠀⠀⠀⠀⠀⢸
   ⡇⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⠀⠀⠀⠀⠀⠀⢸
   ⡇⠀⠀⠙⠀⠀⠀⠀⠀⠀⠀⠀⠀    ⠀⠀⠀⠀⠀⠀⢸
1.5⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
   0.625                  4.375

TODOs

Acknowledgement

Inspired by UnicodePlots.jl.