Gnuplot
Gnuplot narzędzie do tworzenia wykresów
Gnuplot http://www.gnuplot.info/ http://t16web.lanl.gov/kawano/gnuplot/index-e.html
Pomoc help help plotting help polecenie, np. plot test
Polecenie test rotated ce+ntred text pdfcairo 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 -1 filled polygons: 1 2 3 left justified 4 centre+d text 5 right justified 6 7 test of character width: 8 9 123456789123456789 1 11 Enhanced text: xn+1 12 13 14 15 16 pattern fill 17 1 2 3 4 5 6 7 8 9 18 19 2
in/out wejście do programu gnuplot wyjście z programu exit lub quit zachowanie sesji gnuplot> save savefile.gpl wywołanie pliku gnuplota z gnuplota: gnuplot> load savefile.gpl z konsoli: $ gnuplot savefile.gpl
Można też utworzyć skrypt gnuplota pierwsza linijka #!/usr/bin/gnuplot lub #!/usr/bin/env gnuplot
Format pliku wyjściowego gnuplot> set terminal Available terminal types:... fig FIG graphics language for XFIG graphics editor jpeg JPEG images using libgd and TrueType fonts pdfcairo pdf terminal based on cairo png PNG images using libgd and TrueType fonts postscript PostScript graphics language [mode fontname font size] wxt wxwidgets cross-platform windowed terminal x11 X11 Window System...
Format pliku wyjściowego 1. wybór formatu: set terminal postscript set term post color set term post enhanced 2. określenie nazwy pliku wyjściowego: set out plik.ps set out plik.ps
Tworzenie wykresu plot x plot x**2 plot sin(x) f(x) = sin(x*a); a =.2 plot f(x) plot f(x) = sin(x*a), a =.2, f(x), a =.4, f(x) splot sin(x) plot dane.dat
Tworzenie wykresu z legendą lub bez niej plot x**2 title wykres funkcji xˆ2 plot x**2 t wykres funkcji xˆ2 plot x**2 notitle plot x**2 not
Tworzenie wykresu plot x**2 t wykres funkcji xˆ2 with lines lt 4 plot x**2 t wykres funkcji xˆ2 w linesp lt 4 pt 3 plot x**2 notitle w l lt 4 plot x**2 not w lp lt 4 pt 3
Przykład 1 9 wykres funkcji x 2 8 7 6 5 4 3 2 1-1 -5 5 1
Napisy set title Tytuł set xlabel os x set ylabel os y set label opis at 2,3 set label 1 inny opis at 2,3 unset label 1
Przykładowy skrypt #! / u s r / b i n / env g n u p l o t s e t term p o s t enhanced s e t output fun kw. ps s e t t i t l e Wykres f u n k c j i s e t x l a b e l os x s e t y l a b e l os y p l o t x 2 t x ˆ2 w l i n e s p l t 4 pt 3
Przykładowy skrypt #! / u s r / b i n / env g n u p l o t s e t term p o s t enhanced s e t output fun kw. ps s e t t i t l e Wykres f u n k c j i s e t x l a b e l os x s e t y l a b e l os y p l o t x 2 t x ˆ2 w l i n e s p l t 4 pt 3 Wykonanie: 1. chmod +x przyklad.gpl 2../przyklad.gpl 3. gv fun kw.ps
Przykład os y Wykres funkcji 1 9 x 2 8 7 6 5 4 3 2 1-1 -5 5 1 os x
Funkcje wbudowane sqrt(x), exp(x), log(x), log1(x), abs(x), int(x) ceil(x) - najmniejsza liczba całkowita nie mniejsza niż x, floor(x) - największa liczba całkowita nie większa niż x sgn(x) sin(x), cos(x), sinh(x), cosh(x), tan(x), tanh(x), asin(x), asinh(x), acos(x), acosh(x), atan(x), atan2(y,x), atanh(x) imag(x), real(x) norm(x), rand(x)
Własne zmienne i funkcje a=5; b=2.5 liczba zespolona: x={2, 3} a=5*sqrt(7)+1 f(x)=a*sin(x)*tan(x)
Własne zmienne i funkcje 5 4 3 2 1-1 -2-1 -5 5 1
Styl linii i punktów typ linii - lt kolor linii - lc grubość linii - lw typ punktu - pt wielkość punktu - ps
Styl linii i punktów typ linii - lt kolor linii - lc grubość linii - lw typ punktu - pt wielkość punktu - ps plot dane.dat u 1:2 not w lp lt 1 lc 3 lw 3, u 2:3 not w p lc 1 pt 2 ps 3 set style line 1 lc 3 pt 7 ps.3 plot dane.dat not w p ls 1
Styl linii i punktów 16 14 12 1 8 6 4 2 2 4 6 8 1 12 14 16
Własne kolory s e t s t y l e l i n e 1 l t rgb #19c91e pt 5 p l o t dane. dat not w p l c rgb #c227d9 pt 5,\ dane. dat not w p l s 1 ps. 5
Własne kolory s e t s t y l e l i n e 1 l t rgb #19c91e pt 5 p l o t dane. dat not w p l c rgb #c227d9 pt 5,\ dane. dat not w p l s 1 ps. 5 1 8 6 4 2 2 4 6 8 1
Własne kolory s e t key o u t s i d e r e v e r s e s e t format y %.2 f s e t s t y l e l i n e 1 lw 3 l c rgb g o l d s e t s t y l e l i n e 2 lw 2 l c rgb p u r p l e s e t s t y l e l i n e 3 lw 3 l c rgb dark r e d s e t s t y l e l i n e 4 lw 2 l c rgb sea g r e e n s e t s t y l e i n c r e m e n t u s e r p l o t s i n ( x ), cos ( x ), 2 s i n ( x ), 2 cos ( x )
Własne kolory s e t key o u t s i d e r e v e r s e s e t format y %.2 f s e t s t y l e l i n e 1 lw 3 l c rgb g o l d s e t s t y l e l i n e 2 lw 2 l c rgb p u r p l e s e t s t y l e l i n e 3 lw 3 l c rgb dark r e d s e t s t y l e l i n e 4 lw 2 l c rgb sea g r e e n s e t s t y l e i n c r e m e n t u s e r p l o t s i n ( x ), cos ( x ), 2 s i n ( x ), 2 cos ( x ) 2. 1.5 1. sin(x) cos(x) 2*sin(x) 2*cos(x).5. -.5-1. -1.5-2. -1-5 5 1
Własne kolory rgb ( r, g, b ) = 65536 i n t ( r ) + 256 i n t ( g ) + i n t ( b ) p l o t dane. dat using 1 : 2 : ( rgb ( $1, $2 1, $3 1)) \ not with p o i n t s l c rgb v a r i a b l e pt 7 ps. 5
Własne kolory rgb ( r, g, b ) = 65536 i n t ( r ) + 256 i n t ( g ) + i n t ( b ) p l o t dane. dat using 1 : 2 : ( rgb ( $1, $2 1, $3 1)) \ not with p o i n t s l c rgb v a r i a b l e pt 7 ps. 5 1 8 6 4 2 2 4 6 8 1
Ustawienia osi set logscale x unset logscale x set logscale xy set xtics,.5,1 set xtics 5 set format x %.1e set format y %2.t{/Symbol \327}1ˆ{%T}
Ustawienia osi 1 1 6 1 1 5 1 1 4 1 1 3.e+ 1.e+4 2.e+4 3.e+4 4.e+4 5.e+4
Dane z pliku plot dane.dat plot dane.dat using 1:2 plot dane.dat using 1:2 with lines [point, linesp, steps, impulses, dots] plot dane.dat using 1:2 with lines, using 1:3 with impulses plot dane1.dat u 1:2 t 1 i 2 pt 5, u 1:3 t 1 i 3 lc 3 pt 7,\ u 2:3 t 2 i 3 lc 4 pt 9
Dane z pliku 1 'dane.dat' 1 'dane.dat' 1 'dane.dat' 8 8 8 6 6 6 4 4 4 2 2 2 2 4 6 8 1 2 4 6 8 1 2 4 6 8 1 1 'dane.dat' 1 'dane.dat' 1 'dane.dat' 8 8 8 6 6 6 4 4 4 2 2 2 2 4 6 8 1 2 4 6 8 1 2 4 6 8 1
Dane z pliku 16 14 12 16 14 12 1 i 2 1 i 3 2 i 3 1 1 8 8 6 6 4 4 2 2 5 1 15 2 25 3 35 4 45 5 2 4 6 8 1 12 14 16
Niepewności plot dane.dat with errorbars plot dane.dat using 1:2:3 with yerrorbars plot dane.dat using 1:2:3:4 with yerrorbars plot dane.dat using 1:2:3:4 with xyerrorbars plot dane.dat using 1:2:3:4:5:6 with xyerrorbars
Niepewności 18 16 14 12 1 8 6 4 2 5 1 15 2 25 3 35 4 45 5 18 16 14 12 1 8 6 4 2 5 1 15 2 25 3 35 4 45 5 18 16 14 12 1 8 6 4 2 5 1 15 2 25 3 35 4 45 5 55
Serie danych Plik podzielony na serie danych - bloki oddzielone dwiema pustymi liniami: plot dane.dat index using 1:2 not, index 1 not
Serie danych.8.6.4.2 -.2 -.4 -.6 -.8-1 -.8 -.6 -.4 -.2.2.4.6.8 1
Wybrane dane set xrange [-15:1], set xrange [15:-1], set yrange [:1] (plot [:2] f(x); plot [ ][:1] f(x); plot [:2][:1] f(x))
Wybrane dane set xrange [-15:1], set xrange [15:-1], set yrange [:1] (plot [:2] f(x); plot [ ][:1] f(x); plot [:2][:1] f(x)) every I:J:K:L:M:N I - co ile linii J - co ile bloków K - pierwsza linia L - pierwszy blok M - ostatnia linia N - ostatni blok
Wybrane dane set xrange [-15:1], set xrange [15:-1], set yrange [:1] (plot [:2] f(x); plot [ ][:1] f(x); plot [:2][:1] f(x)) every I:J:K:L:M:N I - co ile linii J - co ile bloków K - pierwsza linia L - pierwszy blok M - ostatnia linia N - ostatni blok every 2 - co druga linia every ::3 - od trzeciej linii every ::3::5 - od trzeciej do piątej linii every 2::::6 - linie pierwsza,trzecia,piąta i siódma every :::5::8 - bloki od piątego do ósmego
Przykład s e t xrange [. 9 6 : 1. 2 ] s e t yrange [. 1 :. 1 ] p l o t dane2. dat index every 2 : : : : 6 not pt 7
Przykład s e t xrange [. 9 6 : 1. 2 ] s e t yrange [. 1 :. 1 ] p l o t dane2. dat index every 2 : : : : 6 not pt 7 -.1 -.5.5.1.96.97.98.99 1 1.1 1.2
Modyfikacja danych plot dane.dat using 1:2 with lines plot dane.dat using 1:($2*2) with lines plot dane.dat using 1:(sqrt($2)) with lines plot dane.dat using 1:2:($2*$3/1.) with lines
Przykład p l o t dane. dat u 1 : ( c e i l ( $2)%2==?1: 1) not w p l s 1
Przykład p l o t dane. dat u 1 : ( c e i l ( $2)%2==?1: 1) not w p l s 1 1-1 e+ 1e+4 2e+4 3e+4 4e+4 5e+4
Łączenie plików Polecenie paste: plot <paste dane.dat dane1.dat using 2:4 w lp plot <paste dane.dat dane1.dat using 1:($2/$4) w lp
Sortowanie plot dane.dat not w lp lc 3 pt 7 ps.3 1 8 6 4 2 2 4 6 8 1
Sortowanie plot <sort -n dane.dat not w lp lc 3 pt 7 ps.3 1 8 6 4 2 2 4 6 8 1
Fitowanie 1 dane 8 6 4 2 2 4 6 8 1
Fitowanie f(x)=a*x**b fit f(x) dane.dat via a,b
Fitowanie f(x)=a*x**b fit f(x) dane.dat via a,b plot dane.dat t dane lc 3 pt 7 ps.3, f(x) lc 1
Fitowanie f(x)=a*x**b fit f(x) dane.dat via a,b plot dane.dat t dane lc 3 pt 7 ps.3, f(x) lc 1 1 f(x) dane 8 6 4 2 2 4 6 8 1
Fitowanie f(x)=a*x**b fit f(x) dane.dat via a,b set key left invert reverse plot dane.dat t dane lc 3 pt 7 ps.3, f(x) lc 1 1 f(x) dane 8 6 4 2 2 4 6 8 1
Przykład f ( x)=a x b f i t f ( x ) dane. dat v i a a, b s e t l a b e l a=%g, a,, b=%g, b at 5,82
Przykład f ( x)=a x b f i t f ( x ) dane. dat v i a a, b s e t l a b e l a=%g, a,, b=%g, b at 5,82 1 8 f(x) dane a=1, b=2 6 4 2 2 4 6 8 1
Fit - uwagi f(x)=a*(x**b) fit f(x) przyklad.dat via fit.par gdzie plik fit.par : a=1 b=-1 raport z fitowania zapisywany jest w pliku fit.log
fit.log ******************************************************************************* Thu Mar 8 :11:21 212 FIT: data read from dane.dat format = z #datapoints = 51 residuals are weighted equally (unit weight) function used for fitting: f(x) fitted parameters initialized with current variable values Iteration WSSR : 1.2483e+9 delta(wssr)/wssr : delta(wssr) : limit for stopping : 1e-5 lambda : 181.289 initial set of free parameter values a = 1 b = 1 After 26 iterations the fit converged. final sum of squares of residuals : 2.97522e-23 rel. change during last iteration : degrees of freedom (FIT_NDF) : 49 rms of residuals (FIT_STDFIT) = sqrt(wssr/ndf) : 7.79222e-13 variance of residuals (reduced chisquare) = WSSR/ndf : 6.7187e-25 Final set of parameters Asymptotic Standard Error ======================= ========================== a = 1 +/- 5.293e-16 (5.293e-14%) b = 2 +/- 1.192e-16 (5.962e-15%) correlation matrix of the fit parameters: a b a 1. b -.999 1. *******************************************************************************
Przykład s e t xrange [ 5:5] s e t yrange [ : 1 ] f ( x )=(1/( s1 s q r t (2 p i ) ) ) exp ( (( x m1) 2 ) / ( 2 s1 2)) g ( x )=(1/( s2 s q r t (2 p i ) ) ) exp ( (( x m2) 2 ) / ( 2 s2 2)) f i t f ( x ) r o z k l a d 1. dat v i a s1, m1 f i t g ( x ) r o z k l a d. dat v i a s2, m2 s e t l a b e l s=%.2g, s1,, m=%.2g,m1 at 4,.8 t e x t c o l o r l t 1 s e t l a b e l s=%.2g, s2,, m=%.2g,m2 at 4,.7 t e x t c o l o r l t 3 p l o t r o z k l a d 1. dat not pt 5 ps. 5, f ( x ) not l c 5,\ r o z k l a d. dat not pt 7 ps. 5, g ( x ) not l c 4
Gnuplot 1.8 s=.5, m=1 s=1, m=.13.6.4.2-4 -2 2 4
Alfabet grecki set label {/Symbol s}=%.2g,s1,, {/Symbol m}=%.2g,m1 at -4,.8 textcolor lt 1 set label {/Symbol s}=%.2g,s2,, {/Symbol m}=%.2g,m2 at -4,.7 textcolor lt 3 1.8 σ=.5, µ=1 s=1, µ=.13.6.4.2-4 -2 2 4
Dwie różne osie 1 8 6 4 2 2 4 6 8 1
Dwie różne osie 1 2 8 6 y1 1 y2 4 2 2 4 6 8 1
Dwie różne osie s e t border 11 #bottom 1, l e f t 2, top 4, r i g h t 8 s e t x t i c s n o m i r r o r s e t y t i c s n o m i r r o r s e t y 2 t i c s 1 s e t y l a b e l y1 r o t a t e by s e t y 2 l a b e l y2 p l o t dane. dat u 1 : 2 not l c 3 pt 7 ps. 3, \ u 1 : 3 a x i s x1y2 not l c 1
Multiplot 1.5 1.5 1.5 1-1 1-2 1-3 1 1 1.5.5.5 V -.5 -.5 -.5-1 -1-1 -1.5-1.5-1.5-1.5-1 -.5.5 1 1.5-1.5-1 -.5.5 1 1.5-1.5-1 -.5.5 1 1.5 x x x 1.5 1.5 1.5 1-4 1-5 1-6 1 1 1.5.5.5 V -.5 -.5 -.5-1 -1-1 -1.5-1.5-1.5-1.5-1 -.5.5 1 1.5-1.5-1 -.5.5 1 1.5-1.5-1 -.5.5 1 1.5 x x x
Multiplot s e t term pdf c o l o r enhanced font Times, 3 s e t out m u l t i p l o t. pdf s e t s i z e s q u a r e. 5,. 5 s e t x l a b e l x s e t y l a b e l V r o t a t e by s e t xrange [ 1. 5 : 1. 5 ] s e t yrange [ 1. 5 : 1. 5 ] s e t m u l t i p l o t s e t o r i g i n. 1,. 5 ; p l o t dane. out i n d u 2 :3 t 1ˆ{ 1} w l u n s e t y l a b e l s e t o r i g i n. 2 5,. 5 p l o t dane. out i n d 1 u 2 :3 t 1ˆ{ 2} w l s e t o r i g i n. 5 5,. 5 p l o t dane. out i n d 2 u 2 :3 t 1ˆ{ 3} w l s e t y l a b e l V r o t a t e by s e t o r i g i n.1, p l o t dane. out i n d 3 u 2 :3 t 1ˆ{ 4} w l u n s e t y l a b e l s e t o r i g i n. 2 5, p l o t dane. out i n d 4 u 2 :3 t 1ˆ{ 5} w l s e t o r i g i n. 5 5, p l o t dane. out i n d 5 u 2 :3 t 1ˆ{ 6} w l u n s e t m u l t i p l o t
Multiplot
Multiplot s e t p a r a m e t r i c u n s e t x t i c u n s e t y t i c u n s e t key s e t s i z e s q u a r e. 5,. 5 s e t r m a r g i n s e t m u l t i p l o t s e t o r i g i n.1,.5 p l o t s i n (3 t ), cos (2 t ) s e t o r i g i n. 2 5,. 5 p l o t s i n (3 t ), cos (4 t ) s e t o r i g i n. 5 5,. 5 p l o t s i n (3 t ), cos (5 t ) s e t o r i g i n.1, p l o t s i n (2 t ), cos (2 t ) s e t o r i g i n. 2 5, p l o t s i n (4 t ), cos (3 t ) s e t o r i g i n. 5 5, p l o t s i n (5 t ), cos (2 t ) u n s e t m u l t i p l o t
Multiplot
Multiplot s e t p o l a r u n s e t x t i c u n s e t y t i c u n s e t key s e t s i z e s q u a r e. 5,. 5 s e t r m a r g i n s e t m u l t i p l o t s e t o r i g i n.1,.5 p l o t s i n (3 t ), cos (2 t ) s e t o r i g i n. 2 5,. 5 p l o t s i n (3 t ), cos (4 t ) s e t o r i g i n. 5 5,. 5 p l o t s i n (3 t ), cos (5 t ) s e t o r i g i n.1, p l o t s i n (2 t ), cos (2 t ) s e t o r i g i n. 2 5, p l o t s i n (4 t ), cos (3 t ) s e t o r i g i n. 5 5, p l o t s i n (5 t ), cos (2 t ) u n s e t m u l t i p l o t
Multiplot 6e+3 5e+3 dt 4e+3 3e+3 2e+3 1e+3 1 5 4 e+ e+ 1e+4 2e+4 3e+4 4e+4 5e+4 t
Multiplot s e t key l e f t s e t format x %1. e s e t format y %1. e s e t x t i c s 1 e4 s e t m u l t i p l o t s e t arrow from 2. 5 e4, 2. 5 e3 to 3e3,. 4 e3 f i l l e d l c 1 lw 3 s e t o r i g i n, s e t x l a b e l t s e t y l a b e l dt p l o t dane. out not w l i n e s p l c 3, dane1. out not w l i n e s p l c 4,\ dane2. out not w l i n e s p l c 5 s e t s i z e. 4,. 4 s e t o r i g i n. 5 5,. 2 7 s e t xrange [ : 4 ] u n s e t x l a b e l u n s e t y l a b e l s e t format xy %1. f s e t y t i c s 5 s e t x t i c s 4 re plot u n s e t m u l t i p l o t
Trzy wymiary complex ( x, y)=x {1,}+y {,1} mandel ( x, y, z, n)=( abs ( z ) >2. n>=1)? n : mandel ( x, y, z z+complex ( x, y ), n+1) s e t i s o s a m p l e 5 s e t hidden3d s e t contour s p l o t mandel ( x, y, {, }, ) 1 1 1 1-1.5-1 -.5.5-1 -.5.5 1
Kilka plików z danymi sed s/rozklad.dat/rozklad1.dat/g rozklad.gpl gnuplot for i in rozklad.dat rozklad1.dat rozklad3.dat; do sed s/rozklad.dat/$i/g rozklad.gpl gnuplot; done
Kilka plików z danymi #!/bin/sh sed s/rozklad.dat/rozklad.dat/g rozklad.gpl gnuplot sed s/rozklad.dat/rozklad1.dat/g rozklad.gpl gnuplot sed s/rozklad.dat/rozklad2.dat/g rozklad.gpl gnuplot sed s/rozklad.dat/rozklad3.dat/g rozklad.gpl gnuplot...
Kilka plików z danymi plik rozklad.sh: #!/bin/sh gnuplot << EOF set terminal post eps enhanced set output $1.eps set xrange [ -1 : 1 ] set yrange [ : 2 ] plot $1.dat notitle w l EOF