-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdumbplot
executable file
·83 lines (67 loc) · 2.16 KB
/
dumbplot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# dumbplot: Output plot on the terminal given list of X,Y coordinates.
# Can either be a scatter plot or a bar (or bar-like) plot that
# assumes that the y-coordinate is numeric and just displays the
# x-coordinate data as-is, and in the order that it is fed to the
# scripts.
#
# Dependency: gnuplot
#
# Author: http://jeroenjanssens.com
usage () {
cat << EOF
dumbplot: Use gnuplot to quickly get ascii plot of x-y data.
usage: dumbplot OPTIONS
OPTIONS:
-a As-is. Use the x-coord (first coord) as categorical data for plotting.
-b Boxplot. Use vertical boxes rather than just a marker. Autosets -a switch.
-w Terminal width do use. Defaults to actual terminal width.
-v Terminal height to use. Defaults to terminal height / 2.
-h Show this message
Example usage:
$ paste -d, <(echo 1 2 4 8 9 | tr ' ' '\n') <(echo 1 2 4 2 1 | tr ' ' '\n') | dumbplot
$ paste -d, <(echo a b c d e | tr ' ' '\n') <(echo 1 2 4 10 6 | tr ' ' '\n') | dumbplot -a
$ paste -d, <(echo a b c d e | tr ' ' '\n') <(echo 1 2 4 10 6 | tr ' ' '\n') | dumbplot -b
$ paste -d, <(echo a b c d e | tr ' ' '\n') <(echo 1 2 4 10 6 | tr ' ' '\n') | dumbplot -b -w 80 -v 22
EOF
}
ASIS=
BARCHART=
PWIDTH=$(tput cols)
PHEIGHT=$(tput lines)
PHEIGHT=$(echo $PHEIGHT / 2 | bc)
while getopts "abw:v:" OPTION
do
case $OPTION in
a)
ASIS=1
;;
b)
ASIS=1
BARCHART=1
;;
w)
PWIDTH=$OPTARG
;;
v)
PHEIGHT=$OPTARG
;;
h)
usage
exit 0
;;
esac
done
## Decision logic to execute right gnuplot command
if [ ! -z "$ASIS" ] ; then
if [ ! -z "$BARCHART" ] ; then
# Categorical data, uses boxes in plot
nl -s, -f nl | gnuplot -e "set term dumb size $PWIDTH,$PHEIGHT" -e 'set datafile separator ","; set nokey; plot "-" using 1:3:xtic(2) with boxes'
else
# Categorical data, do NOT use boxes
nl -s, -f nl | gnuplot -e "set term dumb size $PWIDTH,$PHEIGHT" -e 'set datafile separator ","; set nokey; plot "-" using 1:3:xtic(2)'
fi
else
# Scatterplot of data
gnuplot -e "set term dumb size $PWIDTH,$PHEIGHT" -e 'set datafile separator ","; set nokey; plot "-"'
fi