gnuplot-vortrag auf dem BLIT 2010 Stefan Gasterstädt, Simon Kiertscher Institut für Informatik Universität Potsdam 6. November 2010
Potsdam Universityhg Potsdam University found. 1991 5 Faculties Institute of Computer Science Currently about 800 students in computer science (bachelor, master and diploma students) Gasterstädt, Kiertscher 2
Operating Systems and Distributed Systemshg Research Topics Cluster Computing Communication Architectures for High-Performance Cluster Communication, Gigabit Ethernet and InniBand Privacy & Security Privacy-Aware Data Exchange in P2P networks, Secure VoIP Architecture Grid Computing, Grid Services Distributed Runs, Job Resource Brokers, Fault-Tolerant SOA Gasterstädt, Kiertscher 3
Operating Systems and Distributed Systemshg Our Team Gasterstädt, Kiertscher 4
Was ist gnuplot?hg gnuplot is a command-driven interactive function plotting program can be used to plot functions and data points in both two- and three-dimensional plots in many dierent formats designed primarily for the visual display of scientic data copyrighted, but freely distributable [gnuplot FAQ 1.1] Gasterstädt, Kiertscher 5
Interaktive Kommandozeilehg $ gnuplot gnuplot> a=0.25 gnuplot> f(x)=sin(x)*a gnuplot> plot f(x) gnuplot> help plot gnuplot> help style Gasterstädt, Kiertscher 6
gnuplot-skripte (Wiederverwertung)hg $ cat function.plot #!/usr/bin/env gnuplot # set terminal environment set term postscript eps enhanced color "Helvetica" 10 # define global parametrised function func(x,s,a,f)=s+a*sin(x+f) # specify output file set output "function1.eps" # plot function (default layout) plot func(x,0,1,0) Gasterstädt, Kiertscher 7
1 func(x,0,1,0) 0.8 0.6 0.4 0.2 0-0.2-0.4-0.6-0.8-1 -10-5 0 5 10 Gasterstädt, Kiertscher 8
Multi-Plotshg # set title set title "Sinuskurven" set output "function2.eps" # plot three graphs in same figure plot func(x,0,1,0) title "Original-Sinus", \ func(x,28,10,55) title "Gates-Sinus", \ func(x,24,2,55) title "Jobs-Sinus", \ func(x,28,12,69) title "Torvalds-Sinus" Gasterstädt, Kiertscher 9
40 35 Sinuskurven Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus 30 25 20 15 10 5 0-5 -10-5 0 5 10 Gasterstädt, Kiertscher 10
Multi-Plotshg # show background grid set grid # modify ranges set xrange[-5*pi:5*pi] set yrange[-5:55] set output "function3a.eps" # plot same plot again replot Gasterstädt, Kiertscher 11
Sinuskurven 50 Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus 40 30 20 10 0-15 -10-5 0 5 10 15 Gasterstädt, Kiertscher 12
Multi-Plotshg set output "function3b.eps" # plot three graphs using multiplot set multiplot layout 4,1 title "Sinus comparison" plot func(x,0,1,0) title "Original-Sinus" plot func(x,28,10,55) title "Gates-Sinus" plot func(x,24,2,55) title "Jobs-Sinus" plot func(x,28,12,69) title "Torvalds-Sinus" set nomultiplot Gasterstädt, Kiertscher 13
50 40 30 20 10 0 50 40 30 20 10 0 50 40 30 20 10 0 50 40 30 20 10 0 Sinus comparison Sinuskurven Original-Sinus -15-10 -5 0 5 10 15 Sinuskurven Gates-Sinus -15-10 -5 0 5 10 15 Sinuskurven Jobs-Sinus -15-10 -5 0 5 10 15 Sinuskurven Torvalds-Sinus -15-10 -5 0 5 10 15 Gasterstädt, Kiertscher 14
Direkte Funktionenhg set output "function4.eps" # plot three plus direct graph plot func(x,0,1,0) title "Original-Sinus", \ func(x,28,10,55) title "Gates-Sinus", \ func(x,24,2,55) title "Jobs-Sinus", \ func(x,28,12,69) title "Torvalds-Sinus", \ (x-14)*(x+3)*(x+14)/79+14 title "Direktfunktion 3. Grades" Gasterstädt, Kiertscher 15
Sinuskurven 50 Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus Direktfunktion 3. Grades 40 30 20 10 0-15 -10-5 0 5 10 15 Gasterstädt, Kiertscher 16
Layout anpassenhg # modify tics set tics out set xtics nomirror set ytics in nomirror # modify border set border 1+2 # set border 3 set output "function5.eps" replot Gasterstädt, Kiertscher 17
Sinuskurven 50 Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus Direktfunktion 3. Grades 40 30 20 10 0-15 -10-5 0 5 10 15 Gasterstädt, Kiertscher 18
Was sehen wir?hg # set label set xlabel "X-Werte" set ylabel "Div. Funktionswerte" # add border to legend set key box linestyle -1 set output "function6.eps" replot Gasterstädt, Kiertscher 19
Sinuskurven 50 Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus Direktfunktion 3. Grades 40 Div. Funktionswerte 30 20 10 0-15 -10-5 0 5 10 15 X-Werte Gasterstädt, Kiertscher 20
Layout anpassenhg # add minor tics set mxtics 5 set mytics 2 # modify grid set grid xtics ytics mxtics mytics set output "function7.eps" replot Gasterstädt, Kiertscher 21
Sinuskurven 50 Original-Sinus Gates-Sinus Jobs-Sinus Torvalds-Sinus Direktfunktion 3. Grades 40 Div. Funktionswerte 30 20 10 0-15 -10-5 0 5 10 15 X-Werte Gasterstädt, Kiertscher 22
Darstellung anpassenhg # define some line types set style line 1 linetype rgb "#c0c0c0" linewidth 1 set style line 2 linetype 0 linewidth 1 set style line 3 linetype rgb "brown" linewidth 4 \ pointtype 4 pointsize 2 # modify grid's lines set grid xtics ytics mxtics mytics linestyle 1 ls 2 set output "function8.eps" # plot using specific line/points types plot func(x,0,1,0) title "Original-Sinus" with lines ls 3, \ func(x,28,12,69) title "Torvalds-Sinus" with points linestyle 3 Gasterstädt, Kiertscher 23
Sinuskurven 50 Original-Sinus Torvalds-Sinus 40 Div. Funktionswerte 30 20 10 0-15 -10-5 0 5 10 15 X-Werte Gasterstädt, Kiertscher 24
Darstellung anpassenhg # Basiswerte set output "test.eps" test # Basiswerte set terminal png medium enhanced set output "test.png" test Gasterstädt, Kiertscher 25
rotated ce+ntred text Terminal Test rotated by +45 deg rotated by -45 deg linewidth lw 6 lw 5 lw 4 lw 3 lw 2 lw 1 show ticscale left justified centre+d text right justified test of character width: 12345678901234567890 (color) filled polygon: pattern fill 0 1 2 3 4 5 6 7 8 9-1 0 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 Gasterstädt, Kiertscher 26
Gasterstädt, Kiertscher 27
Layout anpassenhg # rearange tics set xtics rotate by -70 set xtics pi set output "function9.eps" replot Gasterstädt, Kiertscher 28
0 Sinuskurven 50 Original-Sinus Torvalds-Sinus 40 Div. Funktionswerte 30 20 10 0-15.708-12.5664-9.42478-6.28319-3.14159 3.14159 6.28319 9.42478 12.5664 15.708 X-Werte Gasterstädt, Kiertscher 29
Layout anpassenhg # name tics set xtics ("sehr wenig" -4*pi, "" -3*pi 1, "wenig" -2*pi, \ "" -1*pi 1, "naja" 0, "" 1*pi 1, "viel" 2*pi, "" 3*pi 1, \ "sehr viel" 4*pi) set output "function10.eps" replot Gasterstädt, Kiertscher 30
Sinuskurven 50 Original-Sinus Torvalds-Sinus 40 Div. Funktionswerte 30 20 10 0 sehr wenig wenig naja viel sehr viel X-Werte Gasterstädt, Kiertscher 31
Zwischenfazithg Gnuplot kann mathematische Berechnungen anstellen, die Funktionswerte plotten und es lassen sich dabei viele Darstellungsparameter anpassen: Achsen (Tiks, Mirror,... ) div. Beschriftungen Legende Positionierung Grid Benutzerspezische Darstellung von Linien, Balken, Punkten,...... Es existieren etliche weitere Darstellungsformen, die insbesondere für externe (Mess-) Daten geeignet sind. lines bars points (with lines (with errorbars)) error bars, error lines, error boxen candle sticks... Gasterstädt, Kiertscher 32
Externe Datenhg $ cat messung.data 1 10 2 20 4 40 5 50 7 70 8 80 Gasterstädt, Kiertscher 33
Externe Daten (Punkte)hg #!/usr/bin/env gnuplot # set terminal environment set term postscript eps enhanced color "Helvetica" 10 # specify output file set output "messung1.eps" # plot data using points plot "messung.data" using 1:2 title "Messdaten XY" \ with points Gasterstädt, Kiertscher 34
80 Messdaten XY 70 60 50 40 30 20 10 1 2 3 4 5 6 7 8 Gasterstädt, Kiertscher 35
Externe Daten (Linien)hg set output "messung2.eps" # plot data using lines plot "messung.data" using 1:2 title "Messdaten XY" \ with lines Gasterstädt, Kiertscher 36
80 Messdaten XY 70 60 50 40 30 20 10 1 2 3 4 5 6 7 8 Gasterstädt, Kiertscher 37
Fortlaufender X-Wert (Punkte)hg set output "messung3.eps" # plot data using index as x-value plot "messung.data" using ($0):2 title "Messdaten XY" \ with points Gasterstädt, Kiertscher 38
80 Messdaten XY 70 60 50 40 30 20 10 0 1 2 3 4 5 Gasterstädt, Kiertscher 39
Fortlaufender X-Wert (Linien)hg set output "messung4.eps" # plot data using lines plot "messung.data" using ($0):2 title "Messdaten XY" \ with lines Gasterstädt, Kiertscher 40
80 Messdaten XY 70 60 50 40 30 20 10 0 1 2 3 4 5 Gasterstädt, Kiertscher 41
Fortlaufender X-Wert (Boxen)hg set output "messung5.eps" # plot data using boxes plot "messung.data" using ($0):2 title "Messdaten XY" \ with boxes Gasterstädt, Kiertscher 42
80 Messdaten XY 70 60 50 40 30 20 10 0 1 2 3 4 5 Gasterstädt, Kiertscher 43
Boxbreitehg set output "messung6.eps" # plot data with explicit boxes' width plot "messung.data" using ($0):2:(0.4) title "Messdaten XY" \ with boxes Gasterstädt, Kiertscher 44
80 Messdaten XY 70 60 50 40 30 20 10-1 0 1 2 3 4 5 6 Gasterstädt, Kiertscher 45
Layout anpassenhg # modify ranges set xrange [0.5:5.5] set yrange [0:85] set output "messung7.eps" # plot same plot again replot Gasterstädt, Kiertscher 46
80 Messdaten XY 70 60 50 40 30 20 10 0 1 2 3 4 5 Gasterstädt, Kiertscher 47
Multiple Datenhg $ cat messung.data2 4 30 7 50 13 150 11 70 2 20 9 130 Gasterstädt, Kiertscher 48
Multiple Datenhg # modify y-range set yrange [0:340] set output "messung8a.eps" # plot data out of two different files plot "messung.data" using ($0):2:(0.4) \ title "Messdaten XY (data)" with boxes, \ "messung.data2" using ($0):2:(0.4) \ title "Messdaten XY (data2)" with boxes Gasterstädt, Kiertscher 49
Messdaten XY (data) Messdaten XY (data2) 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 50
Multiple Daten in einer Quellehg $ cat messung.data3 1 10 2 20 4 40 5 50 7 70 8 80 4 30 7 50 13 150 11 70 2 20 9 130 Gasterstädt, Kiertscher 51
Multiple Daten via Indexhg set output "messung8b.eps" # plot data out of one file using indes plot "messung.data3" index 0 using ($0):2:(0.4) \ title "Messdaten XY (data3:0)" with boxes, \ "messung.data3" index 1 using ($0):2:(0.4) \ title "Messdaten XY (data3:1)" with boxes Gasterstädt, Kiertscher 52
Messdaten XY (data3:0) Messdaten XY (data3:1) 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 53
Multiple Daten via Berechnunghg set output "messung9.eps" # plot data out of one file, plus enlarged data plot plot "messung.data3" index 0 using ($0):2:(0.4) \ title "Messdaten XY" with boxes, \ "messung.data3" index 0 using ($0):($2*4):(0.4) \ title "Vierfaches XY" with boxes Gasterstädt, Kiertscher 54
Messdaten XY Vierfaches XY 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 55
Verbesserte Darstellunghg # modify y-range set yrange [0:360] set output "messung10.eps" # plot two boxes next to each other by shifting its x-values plot "messung.data3" index 0 using ($0-0.2):2:(0.4) \ title "Messdaten XY" with boxes, \ "messung.data3" index 0 using ($0+0.2):($2*4):(0.4) \ title "Vierfaches XY" with boxes Gasterstädt, Kiertscher 56
350 Messdaten XY Vierfaches XY 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 57
Kombination Daten & Funktionenhg # you still can use functions! (outside defined and inside) fact=4 func(x)=x*fact set output "messung11.eps" plot "messung.data3" index 0 using ($0-0.2):2:(0.4) \ title "Messdaten XY" with boxes, \ "messung.data3" index 0 using ($0+0.2):(func($2)):(0.4) \ title "Funktion auf XY" with boxes, \ x*x*x title "Direktfunktion 3. Grades" Gasterstädt, Kiertscher 58
350 Messdaten XY Funktion auf XY Direktfunktion 3. Grades 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 59
Error-Barshg # same plot plus (calculated) boxerrorbars # without additional legend entry fact=4 func(x)=x*fact set output "messung11.eps" plot "messung.data3" index 0 \ using ($0-0.2):2:($2-3*$1):($2+5*$1):(0.4) \ title "Messdaten XY" with boxerrorbars, \ "messung.data3" index 0 using ($0+0.2):(func($2)):(0.4) \ title "Funktion auf XY" with boxes, \ "messung.data3" index 0 using ($0+0.2):(func($2)):(3*$1) \ notitle with errorbars linestyle 2, \ x**3 title "Direktfunktion 3. Grades" Gasterstädt, Kiertscher 60
350 Messdaten XY Funktion auf XY Direktfunktion 3. Grades 300 250 200 150 100 50 0 1 2 3 4 5 Gasterstädt, Kiertscher 61
Integration in ein groÿes Ganzeshg Is gnuplot suitable for scripting? Yes! Gnuplot can read in les containing additional commands during an interactive session be run in batch mode by piping a pre-existing le or a stream of commands to stdin easily be wrapped in a cgi script for use as a web-driven plot generator [gnuplot FAQ 1.4] Gasterstädt, Kiertscher 62
Integration in ein groÿes Ganzeshg Wie übergibt man Werte (Parameter) zu Gnuplot? Variante #1 Integration in ein Shell-Skript: $ cat someplot.sh #!/usr/bin/env bash # synopsis./someplot.sh datafile plotfile "Some Title" gnuplot << EOF set term postscript eps enhanced color "Helvetica" 12 set xrange [0.5:5.5] set yrange [0:85] set output "$2.eps" plot "$1.data" using (\$0):2:(0.4) title "$3" \ with boxes EOF Gasterstädt, Kiertscher 63
Integration in ein groÿes Ganzeshg Variante #2 Seit Version 4.2.5 gibt es einen speziellen Parameter $ cat someother.plot #!/usr/bin/env gnuplot set term postscript eps enhanced color "Helvetica" 12 set xrange [0.5:5.5] set yrange [0:85] set output PLOT.".eps" plot SOURCE.".data" using (\$0):2:(0.4) title "".TITLE \ with boxes EOF $ gnuplot \ > -e "SOURCE='messung';PLOT='inject-e';TITLE='Messung ABC'" \ > someother.plot Gasterstädt, Kiertscher 64
Integration in ein groÿes Ganzeshg Variante #3 Mittels Backticks können Sie an fast jeder Stelle beliebige Shell-Aufrufe starten! Mit! kann ebenfalls ein Shell-Befehl gestartet werden. Wie wäre es mit sort, awk, bc, python, perl,... Gasterstädt, Kiertscher 65
Integration in ein groÿes Ganzeshg # inline shell scripts set xrange [0:10] set yrange [0:1000] set output "messung13.eps" plot "< for i in 1 2 3 4 5 6 7 8 9 10; do \ echo -n \"$i \"; echo \"$i^3\" bc; done" using 1:2 \ title "Shell bc" with lines Gasterstädt, Kiertscher 66
1000 Shell bc 800 600 400 200 0 0 2 4 6 8 10 Gasterstädt, Kiertscher 67
Open Source Alternativenhg plotiucs (http://ploticus.sourceforge.net/) R (http://www.r-project.org/) Octave (http://www.gnu.org/software/octave/) Yorick (http://yorick.sourceforge.net/) Gasterstädt, Kiertscher 68
Gnuplot Literaturhg Gnuplot Homepage: http://www.gnuplot.org/ Demo scripts for gnuplot: http://gnuplot.sourceforge.net/demo/ Gnuplot Manual: http://www.gnuplot.info/docs/gnuplot.html gnuplot tips - not so Frequently Asked Questions: http://t16web.lanl.gov/kawano/gnuplot/index-e.html Dr. David Völker, Grundkurs Gnuplot: http://userpage. fu-berlin.de/~voelker/gnuplotkurs/gnuplotkurs.html Stephan???, Crashkurs Gnuplot: http://www-stud.uni-due.de/~sdstscwe/index.php/ Artikel/1-Sonstige%20Artikel/51-crashkurs-gnuplot errorbar gnuplot demo: http://www.csse.uwa.edu.au/ programming/gnuplot_demos/errorbar/errorbar.html HTML Help Books (u. a. Gnuplot): http://code.google.com/p/ htmlhelp/downloads/list?q=label:chm Gasterstädt, Kiertscher 69
Real-World Examplehg Mehrere Messungdaten einer Messung in einer Datei: $ cat eins_output.dat # tcp messungen # paket size latency bandwith 1 56.568015 0.017678 2 56.641127 0.035310 3 56.958570 0.052670... 1048576 89282.195221 11.744514 # sctp messungen 1 60.016234 0.016662 2 59.682547 0.033511... Gasterstädt, Kiertscher 70
Style Optionenhg Setzen des Ausgabe Terminals: set term postscript eps enhanced color "Helvetica" 10 Rahmen setzen: set border 3 Grids anschalten: set grid Benutzerdenierte Linien-Typen und Farben setzen: set style line 1 linetype 1 linecolor rgb "dark-blue" set style line 2 linetype 1 linecolor rgb "dark-orange" set style line 3 linetype 1 linecolor rgb "dark-green" set style increment user Gasterstädt, Kiertscher 71
Achsen Optionenhg Tics an den Achsen nach auÿen verlagern: set tics out Spiegelung der Tics abschalten: set xtics nomirror set ytics nomirror Label der Achsen setzen: set xlabel "packet size [byte]" set ylabel "bandwith [MB]" Logarithmische x-achse: set logscale x 2 Gasterstädt, Kiertscher 72
Plot Optionenhg Ausgabe setzen: set output "bandwith.eps" Titel der Grak: set title "TCP/SCTP: bandwith" y-range beeinussen (um Legende sichtbar zu machen): set yrange [:15] Plot style lines: set data style lines Plotten der eigentlichen Daten: plot "output.dat" index 0 using 1:2 title "tcp", \ "output.dat" index 1 using 1:2 title "sctp" Gasterstädt, Kiertscher 73
TCP/SCTP: eins bandwith 14 theoretically tcp eins tcp eins sctp 12 10 bandwith [MB] 8 6 4 2 0 1 32 1024 32768 1.04858e+06 packet size [byte] Gasterstädt, Kiertscher 74
262144 TCP/SCTP: eins latency eins tcp eins sctp 65536 16384 latency [usec] 4096 1024 256 64 16 1 32 1024 32768 1.04858e+06 packet size [byte] Gasterstädt, Kiertscher 75
Aufbereiten der Datenhg Daten liegen als Notenliste vor (Matr.Nr., Punkte, Note) 100000 15,0 3,7 100004 0,0 5,0... 100132 23,5 2,0 Daten aufbereiten (Note, Anzahl) # Note Anzahl 1.0 1 1.3 2... 5.0 3 Darstellung der Messdaten als Blockdiagramm und überlagerter Glättungskurve Gasterstädt, Kiertscher 76
Ausgabe der Notenverteilunghg Direkte Angabe für die Balkendarstellung (fs) und gesmoothe Werte für die Kurve plot "notenverteilung.dat" using 1:2:(0.2) title "Haeufigkeit" \ with boxes fs solid 0.7, \ "notenverteilung.dat" using 1:2 smooth bezier \ title "Verteilungskurve" with lines Gasterstädt, Kiertscher 77
8 7 Notenverteilung der Klausur XY Haeufigkeit Verteilungskurve 6 5 Anzahl 4 3 2 1 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 Note Gasterstädt, Kiertscher 78