Wprowadzenie do programu gnuplot
Transkrypt
Wprowadzenie do programu gnuplot
Wprowadzenie do programu gnuplot Bogdan Kreczmer ZPCiR ICT PWR pokój 307 budynek C3 [email protected] Copyright c 2003 Bogdan Kreczmer Niniejszy dokument zawiera materiały do wykładu na temat wizualizacji danych sensorycznych. Jest on udostepiony ˛ pod warunkiem wykorzystania wyłacznie ˛ do własnych prywatnych potrzeb i może on by ć kopiowany wyłacznie ˛ w całości, razem z ninijesza˛ strona˛ tytułowa. ˛ – Skład FoilTEX– gnuplot Główni autorzy: Thomas Williams, Colin Kelley http://www.gnuplot.info/ ftp://ftp.gnuplot.info/pub/gnuplot/ gnuplot jest programem przeznaczonym do: tworzenia rysunków wykresów funkcji jedno i dwuargumentowych (funkcje moga˛ by ć parametryzowane), obrazowania danych pomiarowych, tworzenia wykresów interpolujacych ˛ przebiegi funkcji na podstawie zbioru danych pomiarowych. Przy interpolacji brane sa˛ pod uwage˛ błedy ˛ zwiazane ˛ z zadanymi wartościami. Jest to program zorientowany na polecenia tekstowe w pracy interaktywnej lub wsadowej. gnuplot 1 Tryby pracy Możliwe sposoby pracy z programem gnuplot: Tryb interaktywny SunOS 5> gnuplot gnuplot>_ . . . gnuplot>exit SunOS 5>_ Tryb potokowy SunOS 5> generator_polecen | gnuplot Tryb wsadowy SunOS 5> gnuplot plik_komend.asci gnuplot 2 Podpowiedzi - help gnuplot> help ‘gnuplot‘ is a command-driven interactive function and data plotting program. It is case sensitive (commands and function names written in lowercase are not the same as those written in CAPS). All command names may be abbreviated as long as the abbreviation is not ambiguous. Any number of commands may . . . Help topics available: batch/interactive bugs coordinates copyright glossary graphical new-features old_bugs set show syntax time/date commands environment introduction plotting startup comments expressions line-editing seeking-assistance substitution Help topic: _ gnuplot 3 Najprostszy wykres Praca interakcyjna: gnuplot>plot sin(x) 1 sin(x) 0.8 0.6 0.4 0.2 0 Przetwarzanie wsadowe: -0.2 SunOS 5>gnuplot sin.cmd Plik “sin.cmd”: # # Rysowanie # plot sin(x) # # Zatrzymanie aż do # naciśni˛ ecia klawisza # ENTER # pause -1 gnuplot -0.4 -0.6 -0.8 -1 -10 -5 0 5 10 Rysunek 1: Wykres funkcji sinus. 4 Najprostszy wykres 1 sin(x) plot sin(x) with lines 2 0.8 0.6 0.4 plot sin(x) w l 2 0.2 0 -0.2 -0.4 -0.6 -0.8 Składnia sekcji with dla polecenia plot: -1 -10 -5 0 5 10 with <style> { {linestyle | ls <line_style>} | {{linetype | lt <line_type>} {linewidth | lw <line_width>} {pointtype | pt <point_type>} {pointsize | ps <point_size>}} } <style> = lines | points | linespoints | impulses | dots | steps | fsteps | histeps | errorbars | xerrorbars | yerrorbars | xyerrorbars | boxes | xyerrorbars | boxes | boxerrorbars | boxxyerrorbars | financebars | candlesticks | candlesticks | vector gnuplot 5 Polecenie test rotated ce+ntred text Terminal Test left justified centre+d text right justified 12345678901234567890 test tics -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 gnuplot>show terminal Rysunek 2: Test “terminala”. terminal type is x11 gnuplot>test gnuplot 6 Przykłady stylów rysowania 1 1 1 sin(x) 0.8 0.8 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 -1 -10 -5 0 5 10 -1 -10 plot sin(x) with l lt 2 -5 0 5 10 -1 -10 plot sin(x) with l lt 3 lw 3 1 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 5 10 plot sin(x) with points -1 -10 -5 0 5 10 plot sin(x) with points pt 1 ps 4 1 1 -1 -10 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 10 plot sin(x) with linespoints lt 2 -1 -10 ... 10 sin(x) 0.8 5 5 sin(x) 0.8 0 0 1 sin(x) -5 -5 plot sin(x) with p lt 2 pt 2 ps 8 0.8 -1 -10 10 sin(x) 0.8 0 5 1 0.8 -5 0 sin(x) 0.8 -1 -10 -5 plot sin(x) with l lt 7 lw 9 1 sin(x) gnuplot sin(x) sin(x) 0.8 -5 0 5 10 w linesp lt 3 lw 3 pt 1 ps 4 -1 -10 ... -5 0 5 10 w linesp lt 7 lw 9 pt 2 ps 8 7 Przykłady stylów rysowania 1 1 1 sin(x) 0.8 0.8 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 -1 -10 -5 0 5 10 -1 -10 plot sin(x) with impulses -5 0 5 10 -1 -10 plot sin(x) with i lt 2 lw 2 1 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 5 10 plot sin(x) with steps -1 -10 -5 0 5 10 plot sin(x) w fsteps lt 2 lw 2 1 1 -1 -10 0.6 0.6 0.6 0.4 0.4 0.4 0.2 0.2 0.2 0 0 0 -0.2 -0.2 -0.2 -0.4 -0.4 -0.4 -0.6 -0.6 -0.6 -0.8 -0.8 -0.8 plot sin(x) with boxes 10 10 sin(x) 0.8 5 5 sin(x) 0.8 0 0 1 sin(x) -5 -5 plot sin(x) w histeps lt 3 lw 9 0.8 -1 -10 10 sin(x) 0.8 0 5 1 0.8 -5 0 sin(x) 0.8 -1 -10 -5 plot sin(x) with i lt 3 lw 8 1 sin(x) gnuplot sin(x) sin(x) 0.8 -1 -10 -5 ... 0 5 w candlesticks 10 -1 -10 ... -5 0 5 w candlesticks lt 1 lw 3 10 8 Oś zera Polecenia: gnuplot> set yzeroaxis gnuplot> set xzeroaxis lt 1 lw 3 gnuplot> plot sin(x) 1 sin(x) 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -10 -5 0 5 10 Rysunek 3: Wykres funkcji sinus. gnuplot 9 Z radianów na stopnie Polecenia: gnuplot> set angles degrees gnuplot> plot [0:360] sin(x) 1 sin(x) 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 50 100 150 200 250 300 350 Rysunek 4: Wykres funkcji sinus. gnuplot 10 Funkcje parametryczne set parametric plot sin(t),cos(t) 1 sin(t), cos(t) 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Rysunek 5: Wykres funkcji parametrycznej. gnuplot 11 Wzajemna proporcjonalność osi gnuplot> gnuplot> gnuplot> gnuplot> . . . set size ratio 1 set parametric plot sin(t),cos(t) noratio ratio: 1 2 ratio: 1.33 2 2 sin(t), cos(t) sin(t), cos(t) sin(t), cos(t) 1.5 1.5 1.5 1 1 1 0.5 0.5 0.5 0 0 0 -0.5 -0.5 -0.5 -1 -1 -1 -1.5 -1.5 -1.5 -2 -1.5 -2 -1 -0.5 0 0.5 1 1.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 -2 -1.5 -1 -0.5 0 0.5 1 1.5 set size {{no}square | ratio <r> | noratio} {<xscale>,<yscale>} gnuplot 12 Dane z pliku gnuplot>plot ’’dane.asc’’ 9 "dane.asc" 8 7 6 5 Plik ”dane.asc”: # # Przyklad danych # liczbowych # x y # 2 3 3 7 4 2 4.4 1.2 5 1 7 2 8 6 10 9 gnuplot 4 3 2 1 2 3 4 5 6 7 8 9 10 Rysunek 6: Wykres zadany poprzez zbior punktów. 13 Wczytywanie z wejścia standardowego gnuplot> plot "< awk ’/^ *[^#]/ { print $2, $1}’ dane2.asc" with lines Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 . . . 10 # "< awk ’/ *[ ]/ print $2, $1’ dane2.asc" 9 8 7 6 5 4 3 2 1 gnuplot 2 3 4 5 6 7 8 9 14 Kolejność współrzednych ˛ - using gnuplot> plot ’dane.asc’ using 2:1 with lines 10 ’dane.asc’ using 2:1 9 8 7 Plik ”dane.asc”: # # Przyklad danych # liczbowych # y x # 2 3 3 7 4 2 4.4 1.2 5 1 7 2 8 6 10 9 gnuplot 6 5 4 3 2 1 2 3 4 5 6 7 8 9 Rysunek 7: Wykres zadany poprzez zbior punktów z jawnym wskazaniem współrz˛ednej x i y. 15 Rysowanie wielkości błedu ˛ - errorbars gnuplot> plot "dane2.asc" with errorbars 10 "dane2.asc" 9 8 7 6 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 4 2 0.8 4.4 1.2 0.7 5 1 0.2 7 2 0.6 8 6 0.3 10 9 0.6 gnuplot 5 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 8: Wykres zadany poprzez zbior punktów. 16 Dane razem z poleceniami plot ’-’ with lines, ’-’ notitle with errorbars # # x y Dy 10 # 2 3 0.9 9 3 7 0.5 8 4 2 0.8 7 4.4 1.2 0.7 5 1 0.2 6 7 2 0.6 5 8 6 0.3 4 10 9 0.6 e 3 2 3 0.9 2 3 7 0.5 4 2 0.8 1 4.4 1.2 0.7 0 2 3 4 5 5 1 0.2 7 2 0.6 8 6 0.3 10 9 0.6 e gnuplot ’-’ 6 7 8 9 10 17 Rysowanie wielkości błedu ˛ - errorbars gnuplot> plot "dane2.asc" with lines, "dane2.asc" with errorbars 10 "dane2.asc" "dane2.asc" 9 8 7 6 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 4 2 0.8 4.4 1.2 0.7 5 1 0.2 7 2 0.6 8 6 0.3 10 9 0.6 gnuplot 5 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 9: Wykres zadany poprzez zbior punktów. 18 Rysowanie wielkości błedu ˛ - xyerrorbars gnuplot> plot "dane3.asc" with xyerrorbars 10 "dane3.asc" 9 8 7 6 Plik ”dane3.asc”: # # Przyklad danych # liczbowych # x y Dx Dy # 2 3 0.5 0.9 3 7 0.2 0.5 4 2 0.9 0.8 4.4 1.2 0.4 0.7 5 1 0.6 0.2 7 2 0.8 0.6 8 6 0.4 0.3 10 9 0.4 0.6 gnuplot 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 Rysunek 10: Wykres zadany poprzez zbior punktów z informacja˛ o błedach. ˛ 19 Rysowanie z wygładzaniem gnuplot> plot "dane.asc" smooth csplines 9 ’dane.asc’ 8 7 6 5 Plik ”dane.asc”: # # Przyklad danych # liczbowych # x y # 2 3 3 7 4 2 4.4 1.2 5 1 7 2 8 6 10 9 gnuplot 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 11: Wykres zadany poprzez zbior punktów. Rysunek z wygładzaniem. 20 Rysowanie z wygładzaniem gnuplot> plot ’dane.asc’ smooth csplines w l lw 3,\ ’dane.asc’ smooth bezier w l lt 3 lw 2, "dane.asc" w linesp lt 2 ps 3 9 ’dane.asc’ ’dane.asc’ "dane.asc" 8 7 Plik ”dane.asc”: # # Przyklad danych # liczbowych # x y # 2 3 3 7 4 2 4.4 1.2 5 1 7 2 8 6 10 9 gnuplot 6 5 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 12: Wykresy zadane tym samym zbiorem punktów. 21 Wygładzanie parametryzowane gnuplot>plot ’dane2.asc’ using 1:2:(70) smooth acsplines title "Współczynnik 70",\ ’dane2.asc’ using 1:2:(1) smooth acsplines title "Współczynnik 1",\ ’dane2.asc’ notitle with errorbars 10 Wspolczynnik 30 Wspolczynnik 1 9 8 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 4 2 0.8 4.4 1.2 0.7 5 1 0.2 7 2 0.6 8 6 0.3 10 9 0.6 gnuplot 7 6 5 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 13: Wygładzanie parametryzowane. 22 Wygładzanie parametryzowane gnuplot>plot . . . \ ’dane2.asc’ using 1:2:(40/($3*$3)) smooth acsplines\ title "Wspolczynnik wyliczany" with lines lw 3 10 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 4 2 0.8 4.4 1.2 0.7 5 1 0.2 7 2 0.6 8 6 0.3 10 9 0.6 Wspolczynnik 30 Wspolczynnik 1 Wspolczynnik wyliczany 9 8 7 6 5 4 3 2 1 0 2 3 4 5 6 7 8 9 10 Rysunek 14: Wygładzanie parametryzowane wartościami z trzeciej kolumny. gnuplot 23 Zakres - range gnuplot> plot [1:11] [0:10] ’dane.asc’ with lines 10 ’dane.asc’ # # Drugi sposób: # set xrange [1:11] set yrange [0:10] plot ’dane.asc’ w lines 8 6 4 2 0 2 4 6 8 10 Rysunek 15: Wykres zadany poprzez zbior punktów z własnym ustawieniem zakresu zmian współrz˛ednych. gnuplot 24 Nazwa wykresu - title gnuplot> plot [1:11] [0:10] ’dane.asc’ title "Przykladowe dane" with lines\ ’dane.asc’ smooth bezier notitle w lines 10 Przykladowe dane 8 6 4 2 0 2 4 6 8 10 Rysunek 16: Wykres zadany poprzez zbior punktów z własnym ustawieniem zakresu zmian współrz˛ednych. gnuplot 25 Definiowanie własnych funkcji gnuplot> ogrD(x,d)=x-d gnuplot> ogrG(x,d)=x+d gnuplot> wspol(x,s)=s/(x*x) gnuplot> plot ’dane2.asc’ using 1:(ogrG($2,$3)) title "Ograniczenie gorne" with lines,\ ’dane2.asc’ using 1:(ogrD($2,$3)) title "Ograniczenie dolne" with lines,\ ’dane2.asc’ notitle with errorbars,\ ’dane2.asc’ using 1:2:(wspol($3,40)) smooth acsplines\ title "Wspolczynnik wyliczany" with lines lw 3 10 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 4 2 0.8 4.4 1.2 0.7 . . . Ograniczenie gorne Ograniczenie dolne Wspolczynnik wyliczany 9 8 7 6 5 4 3 2 1 0 2 gnuplot 3 4 5 6 7 8 9 10 26 Parametryzacja wykresu gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> . . . moje_x(x,y)=0.2*($2)*sin($1*3.14/9) moje_y(x,y)=0.2*($2)*cos($1*3.14/9) wspol(x,s)=s/(x*x) set parametric plot ’dane2.asc’ using (moje_x($1,$2)):(moje_y($1,$2))\ title "Krzywa modulowana" with lines,\ ’dane2.asc’ using (moje_x($1,$2)):(moje_y($1,$2)):(wspol($3,40))\ smooth acsplines title "Wygladzony",\ sin(t),cos(t) 2 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 . . . Krzywa modulowana Wygladzony sin(t), cos(t) 1.5 1 0.5 0 -0.5 -1 -1.5 -2 -1.5 gnuplot -1 -0.5 0 0.5 1 1.5 27 Biegunowy układ współrzednych ˛ gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> . . . set grid polar set xtics axis set ytics axis set polar set size ratio 1 plot ’dane2.asc’ using ($1/5):($2/5)\ title "Krzywa modulowana" with lines,\ ’dane2.asc’ using ($1/5):($2/5):(wspol($3,40))\ smooth acsplines title "Wygladzony",\ 3 sin(t), sin(t)+1.5 Krzywa modulowana Wygladzony sin(t) sin(t)+1.5 2 Plik ”dane2.asc”: # # Przyklad danych # liczbowych # x y Dy # 2 3 0.9 3 7 0.5 . . . 1 0 2 1 0 1 2 1 2 gnuplot 28 Siatka i podziałka gnuplot> gnuplot> gnuplot> gnuplot> gnuplot> set y2tics set my2tics 2 set mxtics set grid plot ’dane2.asc’ with lines set grid set grid xtics 9 9 set grid xtics ytics mytics 9 9 ’dane2.asc’ 9 9 ’dane2.asc’ ’dane2.asc’ 8 8 8 8 8 8 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5 5 5 4 4 4 4 4 4 3 3 3 3 3 3 2 2 2 2 2 2 1 1 1 1 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 set grid {{no}{m}xtics} {{no}{m}ytics} {{no}{m}ztics} {{no}{m}x2tics} {{no}{m}y2tics} {polar {<angle>}} { {linestyle <major_linestyle>} | {linetype | lt <major_linetype>} ... gnuplot 29