2 #+TITLE: orgtbl-ascii-plot.el -- plots in ascii-art
3 #+OPTIONS: ^:{} author:Thierry Banel author:Michael Brand toc:nil
5 What about text-only plots in tables ?
7 All in Emacs, without any external package.
11 : | ! | x | sin(x/4) | |
12 : |---+----+-------------+--------------|
13 : | # | 0 | 0 | WWWWWW |
14 : | # | 1 | 0.32719470 | WWWWWWWW |
15 : | # | 2 | 0.61836980 | WWWWWWWWWh |
16 : | # | 3 | 0.84147098 | WWWWWWWWWWW |
17 : | # | 4 | 0.97193790 | WWWWWWWWWWWV |
18 : | # | 5 | 0.99540796 | WWWWWWWWWWWW |
19 : | # | 6 | 0.90929743 | WWWWWWWWWWWu |
20 : | # | 7 | 0.72308588 | WWWWWWWWWW- |
21 : | # | 8 | 0.45727263 | WWWWWWWWh |
22 : | # | 9 | 0.14112001 | WWWWWWV |
23 : | # | 10 | -0.19056796 | WWWWH |
24 : | # | 11 | -0.50127705 | WWW |
25 : | # | 12 | -0.75680250 | Wu |
26 : | # | 13 | -0.92901450 | ; |
27 : | # | 14 | -0.99895492 | |
28 : | # | 15 | -0.95892427 | : |
29 : | # | 16 | -0.81332939 | W. |
30 : | # | 17 | -0.57819824 | WWu |
31 : | # | 18 | -0.27941550 | WWWW- |
32 : | # | 19 | 0.050127010 | WWWWWW- |
33 : | # | 20 | 0.37415123 | WWWWWWWW: |
34 : | # | 21 | 0.65698660 | WWWWWWWWWH |
35 : | # | 22 | 0.86749687 | WWWWWWWWWWW: |
36 : | # | 23 | 0.98250779 | WWWWWWWWWWWH |
37 : | # | 24 | 0.98935825 | WWWWWWWWWWWH |
38 : | # | 25 | 0.88729411 | WWWWWWWWWWW- |
39 : | # | 26 | 0.68755122 | WWWWWWWWWW. |
40 : | # | 27 | 0.41211849 | WWWWWWWWu |
41 : | # | 28 | 0.091317236 | WWWWWWu |
42 : | # | 29 | -0.23953677 | WWWWl |
43 : | # | 30 | -0.54402111 | WWh |
44 : | # | 31 | -0.78861628 | W- |
45 : #+TBLFM: $3=sin($x/3);R::$4='(orgtbl-ascii-draw $3 -1 1)
48 : |---+----+-----+--------------|
55 : | # | 6 | 36 | WW: |
56 : | # | 7 | 49 | WWH |
57 : | # | 8 | 64 | WWWV |
58 : | # | 9 | 81 | WWWWH |
59 : | # | 10 | 100 | WWWWWW |
60 : | # | 11 | 121 | WWWWWWW- |
61 : | # | 12 | 144 | WWWWWWWWl |
62 : | # | 13 | 169 | WWWWWWWWWW. |
63 : | # | 14 | 196 | WWWWWWWWWWWV |
64 : #+TBLFM: $3=$x*$x::$4='(orgtbl-ascii-draw $3 0 200)
66 : | ! | x | sqrt(x) | |
67 : |---+----+-----------+--------------|
70 : | # | 2 | 1.4142136 | WWWW: |
71 : | # | 3 | 1.7320508 | WWWWW: |
72 : | # | 4 | 2 | WWWWWW |
73 : | # | 5 | 2.2360680 | WWWWWWh |
74 : | # | 6 | 2.4494897 | WWWWWWW- |
75 : | # | 7 | 2.6457513 | WWWWWWWH |
76 : | # | 8 | 2.8284271 | WWWWWWWWu |
77 : | # | 9 | 3 | WWWWWWWWW |
78 : | # | 10 | 3.1622777 | WWWWWWWWWu |
79 : | # | 11 | 3.3166248 | WWWWWWWWWH |
80 : | # | 12 | 3.4641016 | WWWWWWWWWW; |
81 : | # | 13 | 3.6055513 | WWWWWWWWWWV |
82 : | # | 14 | 3.7416574 | WWWWWWWWWWW: |
83 : | # | 15 | 3.8729833 | WWWWWWWWWWWl |
84 : | # | 16 | 4 | WWWWWWWWWWWW |
85 : #+TBLFM: $3=sqrt($x)::$4='(orgtbl-ascii-draw $3 0 4)
88 : |---+----+-------------+--------------|
89 : | # | 1 | 1 | WWWWWWWWWWWW |
90 : | # | 2 | 0.5 | WWWWWW |
91 : | # | 3 | 0.33333333 | WWWW |
92 : | # | 4 | 0.25 | WWW |
93 : | # | 5 | 0.2 | WW; |
94 : | # | 6 | 0.16666667 | WW |
95 : | # | 7 | 0.14285714 | Wh |
96 : | # | 8 | 0.125 | Wu |
97 : | # | 9 | 0.11111111 | W- |
98 : | # | 10 | 0.1 | W: |
99 : | # | 11 | 0.090909091 | W. |
100 : | # | 12 | 0.083333333 | W |
101 : | # | 13 | 0.076923077 | H |
102 : | # | 14 | 0.071428571 | H |
103 : | # | 15 | 0.066666667 | V |
104 : | # | 16 | 0.0625 | V |
105 : | # | 17 | 0.058823529 | h |
106 : #+TBLFM: $3=1/$x::$4='(orgtbl-ascii-draw $3 0 1)
111 - Through ELPA (Emacs package system). Add the repository to your =.emacs=:
112 : (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
113 List all packages with =M-x packages-list-packages=,
114 look for =orgtbl-ascii-plot= and install it.
115 - Alternatively, download the lisp file
116 https://github.com/tbanel/orgtblasciiplot/blob/master/orgtbl-ascii-plot.el
117 and load it (for example by typing
118 =M-x load-file RET orgtbl-ascii-plot.el RET=)
120 2- Put the cursor on the column to plot.
124 - or =M-x orgtbl-ascii-plot=
125 This adds a new ascii-art column.
127 4- The width in characters of the plot may be specified
128 with a numeric prefix:
130 - =Esc 30 M-x orgtbl-ascii-plot=
134 The column containing the plot has a column formula.
135 When the data column changes, refresh the plot with =C-u C-c *=.
137 The plotting column may be handled in the same way as any other:
138 - remove with =M-S-left=
139 - moved left with =M-left=
140 - moved right with =M-right=
142 The column formula may be changed. Here is how it works:
143 : '(orgtbl-ascii-draw $3 15 75 12)
144 - =$3= is the reference to the data column, here the third column.
145 - =15= is the minimum value to be displayed
146 (values lower than that will display "too small")
147 - =75= is the maximum value to be displayed
148 (values higher than that will display "too large")
149 - =12= is the width of the column,
150 it is optional, and defaults to =12=
152 * Lisp code (pure ascii)
155 https://github.com/tbanel/orgtblasciiplot/blob/master/orgtbl-ascii-plot.el
157 * Example of extension: unicode characters
158 Here are two examples of different styles.
160 Unicode block characters are used to give a smooth effect.
161 See https://en.wikipedia.org/wiki/Block_Elements.
162 Use one of those drawing functions:
163 - =orgtbl-ascii-draw= (the default ascii)
164 - =orgtbl-uc-draw-grid= (unicode with a grid effect)
165 - =orgtbl-uc-draw-cont= (smooth unicode)
167 This is best viewed with the "DejaVu Sans Mono" font (use =M-x set-default-font=).
169 Be aware that unicode support is not available everywhere.
170 For instance, LaTex export will not work.
171 If you plan to export your Org document,
172 either draw pure ascii plots,
173 or use ascii plots only for quick and throwable visualization.
175 : | ! | x | sin(x/4) | ascii | uc grid | uc cont |
176 : |---+----+-------------+--------------+--------------+--------------|
177 : | # | 0 | 0 | WWWWWW | ▉▉▉▉▉▉ | ██████ |
178 : | # | 1 | 0.32719470 | WWWWWWWH | ▉▉▉▉▉▉▉▊ | ███████▉ |
179 : | # | 2 | 0.61836980 | WWWWWWWWWh | ▉▉▉▉▉▉▉▉▉▋ | █████████▋ |
180 : | # | 3 | 0.84147098 | WWWWWWWWWWW | ▉▉▉▉▉▉▉▉▉▉▉ | ███████████ |
181 : | # | 4 | 0.97193790 | WWWWWWWWWWWV | ▉▉▉▉▉▉▉▉▉▉▉▊ | ███████████▊ |
182 : | # | 5 | 0.99540796 | WWWWWWWWWWWW | ▉▉▉▉▉▉▉▉▉▉▉▉ | ████████████ |
183 : | # | 6 | 0.90929743 | WWWWWWWWWWW; | ▉▉▉▉▉▉▉▉▉▉▉▍ | ███████████▍ |
184 : | # | 7 | 0.72308588 | WWWWWWWWWW- | ▉▉▉▉▉▉▉▉▉▉▎ | ██████████▎ |
185 : | # | 8 | 0.45727263 | WWWWWWWWh | ▉▉▉▉▉▉▉▉▋ | ████████▊ |
186 : | # | 9 | 0.14112001 | WWWWWWV | ▉▉▉▉▉▉▊ | ██████▊ |
187 : | # | 10 | -0.19056796 | WWWWV | ▉▉▉▉▊ | ████▊ |
188 : | # | 11 | -0.50127705 | WWH | ▉▉▊ | ██▉ |
189 : | # | 12 | -0.75680250 | W; | ▉▍ | █▍ |
190 : | # | 13 | -0.92901450 | ; | ▎ | ▍ |
191 : | # | 14 | -0.99895492 | | | |
192 : | # | 15 | -0.95892427 | : | ▏ | ▏ |
193 : | # | 16 | -0.81332939 | W. | ▉ | █ |
194 : | # | 17 | -0.57819824 | WWu | ▉▉▍ | ██▌ |
195 : | # | 18 | -0.27941550 | WWWW- | ▉▉▉▉▎ | ████▎ |
196 : | # | 19 | 0.050127010 | WWWWWW- | ▉▉▉▉▉▉▎ | ██████▎ |
197 : | # | 20 | 0.37415123 | WWWWWWWW: | ▉▉▉▉▉▉▉▉▏ | ████████▎ |
198 : | # | 21 | 0.65698660 | WWWWWWWWWH | ▉▉▉▉▉▉▉▉▉▊ | █████████▉ |
199 : | # | 22 | 0.86749687 | WWWWWWWWWWW: | ▉▉▉▉▉▉▉▉▉▉▉▏ | ███████████▏ |
200 : | # | 23 | 0.98250779 | WWWWWWWWWWWH | ▉▉▉▉▉▉▉▉▉▉▉▊ | ███████████▉ |
201 : | # | 24 | 0.98935825 | WWWWWWWWWWWH | ▉▉▉▉▉▉▉▉▉▉▉▊ | ███████████▉ |
202 : | # | 25 | 0.88729411 | WWWWWWWWWWW- | ▉▉▉▉▉▉▉▉▉▉▉▎ | ███████████▎ |
203 : | # | 26 | 0.68755122 | WWWWWWWWWW. | ▉▉▉▉▉▉▉▉▉▉▏ | ██████████▏ |
204 : | # | 27 | 0.41211849 | WWWWWWWW; | ▉▉▉▉▉▉▉▉▍ | ████████▍ |
205 : | # | 28 | 0.091317236 | WWWWWWu | ▉▉▉▉▉▉▍ | ██████▌ |
206 : | # | 29 | -0.23953677 | WWWWu | ▉▉▉▉▍ | ████▌ |
207 : | # | 30 | -0.54402111 | WWh | ▉▉▋ | ██▋ |
208 : | # | 31 | -0.78861628 | W: | ▉▏ | █▎ |
209 : #+TBLFM: $3=sin($x/3);R::$5='(orgtbl-uc-draw-grid $3 -0.99895492 0.99540796 12)::$6='(orgtbl-uc-draw-cont $3 -0.99895492 0.99540796 12)::$4='(orgtbl-ascii-draw $3 -0.99895492 0.99540796 12)
213 Below is a unicode ASCII art solution with Zach Holman's shell script
214 package Spark: https://github.com/holman/spark
216 : | Measurement | t0 | t1 | t2 | t3 | t4 | t5 | t6 | t7 | Sparkline |
217 : |-------------+----+----+----+----+-----+----+----+----+-----------|
218 : | 1 | 1 | 20 | 12 | 13 | 141 | 13 | 24 | 90 | ▁▁▁▁█▁▂▅ |
219 : | 2 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ▁▂▃▄▅▆▇█ |
220 : | 3 | 0 | 2 | 4 | 6 | 8 | 10 | 12 | 14 | ▁▂▃▄▅▆▇█ |
221 : | 4 | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 0 | ▁▂▃▄▅▆▇█ |
222 : | 5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ▅▅▅▅▅▅▅▅ |
223 : #+TBLFM: $10 = '(org-trim (shell-command-to-string "spark $2..$9")); L
225 An ongoing discussion [2015-01-08] is taking place on the Org mailing list about
226 /sparlines/ (https://en.wikipedia.org/wiki/Sparkline) by Willem Rein
227 Oudshoorn and Michael Brand which could end in yet another way of
231 Copyright (C) 2013-2014 Thierry Banel, Michael Brand
233 Authors: Thierry Banel, Michael Brand
235 Keywords: table, plot, ascii, unicode
237 orgtbl-ascii-plot.el is free software: you can redistribute it
238 and/or modify it under the terms of the GNU General Public License
239 as published by the Free Software Foundation, either version 3 of
240 the License, or (at your option) any later version.
242 orgtbl-ascii-plot.el is distributed in the hope that it will be
243 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
244 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
245 GNU General Public License for more details.
247 the GNU General Public License can be obtained here:
248 <http://www.gnu.org/licenses/>.