Thursday, October 17, 2013

Plotting Multiple Lines in GNUplot.

The end goal is to take a comma separated file and plot each value on a line graph using Gnuplot.  Nice X and Y axis labels and a color coded key will be included.   


The input file (wireless-devices2.csv) looks like this:

1377617462, 73, 251, 262, 633, 708, 1476, 454, 386, 466, 145, 608, 294, 895, 606, 336, 7612
1377617753, 69, 238, 263, 610, 692, 1392, 445, 378, 453, 135, 645, 280, 914, 613, 357, 7504
1377618054, 71, 218, 257, 601, 681, 1399, 439, 377, 398, 126, 630, 298, 933, 598, 363, 7408
1377618348, 60, 205, 259, 595, 686, 1412, 441, 363, 394, 131, 680, 299, 948, 601, 366, 7462
1377618649, 70, 209, 268, 595, 679, 1429, 419, 358, 394, 126, 662, 314, 946, 622, 376, 7485
1377618958, 76, 228, 268, 632, 683, 1420, 415, 369, 419, 128, 669, 314, 957, 643, 378, 7617
1377619259, 75, 232, 264, 663, 681, 1414, 422, 389, 439, 140, 724, 317, 962, 642, 374, 7758
1377619555, 80, 247, 268, 669, 687, 1397, 421, 405, 476, 140, 712, 342, 981, 645, 364, 7852
1377619854, 88, 255, 266, 671, 687, 1377, 425, 403, 491, 133, 749, 360, 1000, 658, 365, 7946
1377620161, 96, 253, 259, 666, 669, 1331, 416, 421, 522, 151, 777, 364, 996, 682, 378, 8000

The Gnuplot configuration (wd-total.gnuplot) file looks like this:

set datafile separator ","
set terminal png size 2000,600
set title "Wireless Users"
set ylabel "Wireless Users"
set ytics autofreq 500
set xlabel "Date"
set xdata time
set timefmt "%s"
set format x "%m/%d"
set key left top horizontal
set grid
plot "wireless-devices2.csv" using 1:2 with lines title 'Broken Device', \
  "wireless-devices2.csv" using 1:3 with lines title 'Meru Guest', \
  "wireless-devices2.csv" using 1:4 with lines title 'Meru WUFI', \
  "wireless-devices2.csv" using 1:5 with lines title 'Meru WUFI-S', \
  "wireless-devices2.csv" using 1:6 with lines title 'S40 wustl-guest-1.0', \
  "wireless-devices2.csv" using 1:7 with lines title 'S40 wustl-1.0', \
  "wireless-devices2.csv" using 1:8 with lines title 'S40 wustl-encrypted-1.0', \
  "wireless-devices2.csv" using 1:9 with lines title 'wustl-guest-1.0', \
  "wireless-devices2.csv" using 1:10 with lines title 'wustl-1.0', \
  "wireless-devices2.csv" using 1:11 with lines title 'wustl-encrypted-1.0', \
  "wireless-devices2.csv" using 1:12 with lines title 'Cisco WUFI-S', \
  "wireless-devices2.csv" using 1:13 with lines title 'Cisco WUFI', \
  "wireless-devices2.csv" using 1:14 with lines title 'wustl-2.0', \
  "wireless-devices2.csv" using 1:15 with lines title 'wustl-guest-2.0', \
  "wireless-devices2.csv" using 1:16 with lines title 'wustl-encrypted-2.0', \
  "wireless-devices2.csv" using 1:17 with lines lw 3 title 'TOTAL'


From the command line execute Gnuplot with the configuration file and image redirection as follows:


$ gnuplot < wd-total.gnuplot > wirelessdevices.png

The resulting file should look like this:








No comments:

Post a Comment

Followers