Last active
October 13, 2015 23:38
-
-
Save krtx/4274090 to your computer and use it in GitHub Desktop.
usage:
./svm_plot.sh sample_data graph_data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
vector=$1 | |
border=$2 | |
/usr/bin/gnuplot <<EOF | |
ismin(x) = (x<min)?min=x:0 | |
ismax(x) = (x>max)?max=x:0 | |
grabx(x)=(x<x0)?x0=x:(x>x1)?x1=x:0 | |
graby(y)=(y<y0)?y0=y:(y>y1)?y1=y:0 | |
x0 = 1e38 | |
x1 = -1e38 | |
y0 = 1e38 | |
y1 = -1e38 | |
set table "/dev/null" | |
plot "${vector}" u (grabx(\$1)):(graby(\$2)) | |
unset table | |
set view map | |
set contour | |
set cntrparam linear | |
set cntrparam levels discrete 0 | |
unset surface | |
set table 'contour' | |
splot "${border}" with lines linetype 2 lc rgb "black" | |
unset table | |
unset contour | |
mgn = ((x1 - x0 > y1 - y0) ? x1 - x0 : y1 - y0) * 0.05 | |
set xrange[x0 - mgn:x1 + mgn] | |
set yrange[y0 - mgn:y1 + mgn] | |
set size 1, 1 | |
set terminal png | |
plot 'contour' w l lw 1.5 lc rgb "black" notitle, "${vector}" u 1:2:(\$3 < 0 ? 0 : 1/0) w p pt 19 lc rgb "blue" notitle, "${vector}" u 1:2:(\$3 > 0 ? 0 : 1/0) w p pt 19 lc rgb "red" notitle | |
EOF | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment