added python based tsvplot
This commit is contained in:
41
tsv/tsvplot
41
tsv/tsvplot
@@ -1,33 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
[[ -z "$3" ]] && {
|
||||
_helpexit() {
|
||||
self=$( basename $0 )
|
||||
echo "Plot2D for console.
|
||||
|
||||
Arguments
|
||||
tsvplot FILE xCol yCol [plotStyle] [preBlock]
|
||||
$self FILE xCol yCol [-X] [plotStyle] [preBlock]
|
||||
|
||||
e.g. tsvplot cal.tsv 2 4
|
||||
or tsvplot cal.tsv Area Weight \"with lines;\" \"set title 'test plot';\"
|
||||
e.g. $self cal.tsv 2 4
|
||||
or $self cal.tsv Area Weight \"with lines;\" \"set title 'test plot';\"
|
||||
preBlock may contain any GNUPlot commands.
|
||||
plotStyle contains any plotting style commands.
|
||||
|
||||
-X use X11 instead of console
|
||||
Requires csvkit and gnuplot
|
||||
"
|
||||
exit
|
||||
}
|
||||
|
||||
fbase=$( basename "$1" )
|
||||
if [ $# -lt 3 ]; then _helpexit; fi
|
||||
|
||||
csvcut -t -c "$2,$3" "$1" | gnuplot -e "
|
||||
set term dumb $(tput cols) $(tput lines) enhanced;
|
||||
POS=0
|
||||
POSADJUST=0
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
POS=$(( $i + $POSADJUST ))
|
||||
[[ ${!i} = "-h" ]] && _helpexit
|
||||
[[ ${!i} = "help" ]] && _helpexit
|
||||
[[ ${!i} = "-X" ]] && PLOTTERM=" " && POSADJUST=$(( $POSADJUST - 1 )) && continue
|
||||
[[ $POS -eq 1 ]] && FILE="${!i}"
|
||||
[[ $POS -eq 2 ]] && XCOL="${!i}"
|
||||
[[ $POS -eq 3 ]] && YCOL="${!i}"
|
||||
[[ $POS -eq 4 ]] && STYLE="${!i}"
|
||||
[[ $POS -eq 5 ]] && PRE="${!i}"
|
||||
done
|
||||
fbase=$( basename "$FILE" )
|
||||
[[ -z "$PLOTTERM" ]] && PLOTTERM="set term dumb $(tput cols) $(tput lines) enhanced;"
|
||||
[[ -z "$PRE" ]] && PRE="set title '$fbase';"
|
||||
|
||||
csvcut -t -c "$XCOL,$YCOL" "$FILE" | gnuplot -p -e "$PLOTTERM
|
||||
set datafile separator \",\";
|
||||
set xlabel '$2';
|
||||
$5
|
||||
plot '<cat' using 1:2 title '$fbase $3' $4"
|
||||
set xlabel '$XCOL';
|
||||
set ylabel '$YCOL';
|
||||
$PRE
|
||||
plot '<cat' using 1:2 title '' $STYLE"
|
||||
|
||||
[[ $? -ne 0 ]] && {
|
||||
echo -n "Possible columns: "
|
||||
head -n 1 "$1" | tr \\t ,
|
||||
head -n 1 "$FILE" | tr \\t ,
|
||||
} || {
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user