Вы находитесь на странице: 1из 21

Gnuplot

. .
14 2005 .

.
. , , . ,
,
( , , , - ).

Gnuplot?

2 Gnuplot

Gnuplot

6 Gnuplot

12

19

1 Gnuplot?
Gnuplot ,
. , . , + Gnuplot
, * .
, Gnuplot . ,
help PLOT, Gnuplot .
, . , f(x)
F(x) ( ), .

(
).
: cd "mydir"
pwd
, Linux ,

: pwd
reset , .
: reset
help , .
Gnuplot. , .
( Gnuplot)
, .
splot
: help splot
cd

, Gnuplot
xrange
, . set xrange[{min}:{max}]. {min} {max} , .
* (
).
:
set xrange[0:10] 0, 10
set xrange[*:1.2] , 1, 2
set xrange[-0.98:*] 0, 98, Gnuplot
reset
yrange
, xrange, .
key
, , . - ,
set nokey, .
set key {text}.
: set key This is the graph of Bessel function
3

terminal
, Gnuplot .
, .
(, ),
set terminal {terminal-type}.
{terminal-type} help set terminal.
:
set terminal postscript Gnuplot PostScript.
set terminal X11 X11 Linux,
Gnuplot .
set terminal windows , ,
Windows
set terminal latex LATEX.
LATEX, ,
, .
output
. set output {filename}
, terminal, Gnuplot ( ). ,

gnuplot>set terminal postscript
gnuplot>plot sin(x)
PostScript (
). .
: set output "myfile.ps" ( )
myfile.ps.
. : ,
, set output
, .

Gnuplot

, ,
Gnuplot. ,
( C Python !). ,
.
, , .
-, ,
. , ,
f (x) = a sin x,
a , 12 .
Gnuplot,
( ,
)
4

gnuplot>
gnuplot>
gnuplot>
1
gnuplot>
0

a = 1
b = 2
print a
print a/b

, Gnuplot 1 2 . ,
1 .
, , . :
Gnuplot , , . , 4 , 4. .

(
) Gnuplot plot.

plot {<ranges>} {<function>}
{axes <axes>} {<title-spec>} {with <style>}
{, {definitions,} <function> ...}

<ranges>
{<ranges>} ,
.

[{<dummy-var>=}{{<min>}:{<max>}}]
, {<dummy-var>}, 2. ,
, , x. {<min>} {<max>}
. , , * (
Gnuplot ).

[{{<min>}:{<max>}}]
{{<min>} {<max>}} , .
,
, :
x, y. trange, xrange
yrange.

sin x (
set, Gnuplot )
gnuplot>plot sin(x)
1 ,
2

a b p, , a = pb + q, 0 6 q < 1

, [, ]
gnuplot>plot [t=-pi:pi] sin(t)
, t

gnuplot>plot [-pi:pi] [-0.5:0.5] sin(x)

gnuplot>plot [0:*] [*:0.5] sin(x)

<function>
Gnuplot, .
.
Gnuplot ,
C, Pascal Basic. ,
Gnuplot 3 .


2.35 1.6
gnuplot>plot 1/sqrt(2)/sqrt(pi)*exp(-(x-2.35)**2/1.6**2)
(,
, ). ,
gnuplot>p(x)=sin(x)*exp(-x**2)
gnuplot> plot p(x), p(x+1)

{<title-spec>}
, .
title "<title>"|notitle
, .
, ( ). .
\t4 , .
, notitle
( title ).

, , ( ,
,
)
gnuplot>plot besj0(x) title 0th Bessel function,
3

A
,

{with}
Gnuplot (,
, ).

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, boxerrorbars, boxxyerrorbars, financebars,
candlesticks vectors. .

Gnuplot

5 plot,
( ).

plot <file_name> {index <index list>}
{every <every list>}
{thru <thru expression>}
{using <using list>}
{smooth <option>}
{index <index list>}
(
). .

plot file index <m>{{:<n>}:<p>}


(, index 1),
; (index 1:3) ,
1, 2, 3. ,
. , , index 0:10:2
0, 2, 4, 6, 8 10.
,
{every <every list>}
.

plot file every {<point_incr>}
{:{<block_incr>}
{:{<start_point>}
{:{<start_block>}
{:{<end_point>}
{:<end_block>}}}}}
5

. <start_point>,
<end_point>. <point_incr>.
.6
{thru <thru expression>}
Gnuplot. ,
plot file thru f(x)

plot file using 1:(f($2))
{using <using list>}
, using .

plot file using {<entry> {:<entry> {:<entry> ...}}} {format}


, scanf
7 . , Gnuplot : , (
). .
. ,
( y ,
x ),
gnuplot> plot "datafile.dat" using 1:2
. ,
0, .
. , . datafile.1.dat .

gnuplot> plot datafile.1.dat u 1:(sin(pi*$2))
Gnuplot :
( , , ) z = sin .
(x, z).
, : x , 1, y
sin y
smooth
Gnuplot .
smooth. , (,
). Gnuplot:
gnuplot> help smooth
6 , . , index every
7 Gnuplot : help plot datafyle

Gnuplot , , . -.
plot:
, . , .
:
gnuplot> plot - with linespoints
> 1 2
> 2 1
> 3 4
> e
e (
).
, Gnuplot ,
. , replot, , .
Gnuplot .

Gnuplot

Gnuplot , .
, Gnuplot
. ,
Gnuplot.
,
. ,
, . .
if . ,
:
if (<condition>) <command-line>;
if (<condition>) <command-line1>; else <command-line2>
<condition> <commanf-line>.
<command-line1>,
<command-line2>. , Gnuplot ,
if (1>0) print +;
else print -
. , Gnuplot . ,
if.
1>0 , Gnuplot +
, else.
if , . ,
,
C.
if .
:
9

if (<condition1>) <command-line1>;
else if (<condition2>) <command-line2>;
else if ...
else <command-linen>;
<condition1>. ,
<command-line1> .
<condition2> , <command-line2> .
, ( ,
<command-linen>).
Gnuplot . , , . , .
pause. :
pause <time> {"<string>"}
pause mouse {"string"}
<string>
<time>. time .
, -1,
pause -1 Please press any key
. 0
. ,
pause 0 A-A-A
print
print A-A-A
time , .
, mouse,
, Control-C. , , ,
Gnuplot ( - ).
load .
load <filename>
, . , (,
).
Gnuplot , reread. reread .
,
f (x) =

1
1 + ax2

a. : plotter,

10

#
n = n+1
plot 1/(1+n*1.2*x*x)
pause -1 Press any key to continue
if (n < 10) reread
8 .
. cycle:
#
n = 1
set xrange[-3:3]
set yrange[0:1]
load plotter
,
gnuplot cycle
, .
load:
gnuplot> load cycle
, , plotter
cycle.
Gnuplot , load call:
call <input-file> <option1> <option2> ... <optionn10>
, 10 .
Gnuplot <input-file>,
$n, n 0 10. ,
.
4.0 Gnuplot , , bind.
Gnuplot. ,
bind a print 1
, a ( ,
!) .

: ,

11

3.5

lines
. linewidth linetype
.

gnuplot> plot "datafile.dat"with lines


>linetype 1 lw 1

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

points
.
pointtype ( pt),
pointsize ( ps)

gnuplot> plot "datafile.dat"with points


>pt 3 ps 4

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

linespoints lines
points: , . : linewidth, linetype, pointtype
pointsize

gnuplot> plot "datafile.dat" with linespoints \ >pt 2

2.5

1.5

0.5
0.5

1.5

2.5

3.5

12

3.5

impulses
x

plot "datafile.dat" with impulses

2.5

1.5

0.5
0.5

1.5

2.5

3.5

dots ,
. ( ,
!).

gnuplot> plot "datafile.dat" with dots

3.5

steps , ,
gnuplot> plot "datafile.dat" with steps

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

fsteps . .
, .

2.5

1.5

0.5
0.5

1.5

2.5

3.5

13

3.5

histeps. .
.
(x0 , y0 ), (x1 , y1 ) (x2 , y2 )
. Gnuplot ,





x0 + x 1
x1 + x 2

, y1
, y1 .
2
2

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

( y = y0
y = y2 ). ,
.

gnuplot> plot "datafile.dat" with histeps

errorbars yerrorbars.
,
. :
, .
(x, y )
(x, y + ), (x, ylow )
(x, yhigh ). Gnuplot : ,
, .

gnuplot> plot [0.5:3.5] "datafile.dat" \


>notitle with errorbars

xerrorbars
. , . ,
errorbars

2.5

1.5

0.5
0.5

1.5

2.5

3.5

14

3.5

xyerrorbars , , .
,
errorbars.

gnuplot> plot [0.5:3.5] "datafile.dat" \


>using 1:2:(0.1):(0.2) notitle\
>with xyerrorbars

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

2.5

1.5

0.5
0.5

1.5

2.5

3.5

boxes .
, x, .
Gnuplot .
, . , , set boxwidth.
,
,
.

gnuplot> plot [0.5:3.5] [*:3.05] \


>"datafile.dat"\
>using 1:2:(0.95) notitle with boxes

15

3.5

2.5

1.5

0.5
0.5

1.5

2.5

3.5

3.5

boxerrorbars .
boxes yerrorbars.
: , .
.

gnuplot> plot [0.5:3.5] [0.3:*] \


>"datafile.dat" \
>u 1:2:($2-0.1):($2+0.2):(0.8) \
>notitle with boxerrorbars
,
.

boxxyerrorbars boxes
xyerrorbars. ,
.

gnuplot> plot "datafile.dat" \


> u 1:2:($2-0.1):($2+0.1):($1-0.1):($1+0.2) \
> with boxerrorbars

2.5

1.5

0.5
0.5

1.5

2.5

3.5

16

3.5

2.5

1.5

0.5
0.5

1.5

2.5

3.5

financebars
(, ). :
x ( ),
, , .
,
.
, , ,
. bar ( set bar).

gnuplot>set bar 5
gnuplot>plot [0.5:3.5] "datafile.dat" \
>notitle with financebars

. , , .

3.5

2.5

1.5

0.5
0.5

1.5

2.5

3.5

candlesticks . : x ( ), , , . ,
x
.
. bar.

gnuplot> set bar 5


gnuplot> plot [0.5:3.5] "datafile.dat" \
>notitle with candlesticks
bar.

17

3.5

vectors (, ).
(x, y) (x + x, y + y) (
).
, .
gnuplot>plot "datafile.dat" with vectors

2.5

1.5

0.5
0.5

1.5

2.5

3.5

18


Gnuplot
abs(x)
acos(x)
acosh(x)
arg(z)
asin(x)
asinh(x)
atan(x)
atan2(x,y)
atanh(x)
besj0(x)
besj1(x)
besy0(x)
besy1(x)
ceil(x)
column(x)
cos(x)
cosh(x)
erf(x)

. , .
arccos x

. ( set angles)
arcsin x

arctg x
x y

0
1
0
1
, x. , x.

cos x

Rx t2
e dt
Erf x =

erfc(x)
exp(x)
floor(x)
gamma(x)
ibeta
igamma
imag
int
inverf
invnorm
lgamma
log
log10
norm
rand
real
sgn
sin
sinh
sqrt
tan
tanh
tm_hour
tm_mday

x ,
1 Erf x

x
(x)

, Erf x




, [1, 1]






19

tm_min
tm_mon
tm_sec
tm_wday
tm_yday
tm_year
valid

**
*
/

5**3
5*3
5/3

a%b

+
==
!=
<
<=
>
>=
&
^
|
&&
||

a+b
a-b
a==b
a!=b
a<b
a<=b
a>b
a>=b
a&b
a^b
a|b
a&&b
a||b

( )

( )







*
*
*
*
*

+
~
!
!
$

-a
+a
~a
!a
a!
$3



* ones complement
*
*
9

Gnuplot ( )

?:

a?b:c

, C. , ( ). ,
9

20

.
.

, f (x),
(
sin(x) 1 6 x 6 2
f (x) = 1
(1)
2 < x 6 3
x
:
gnuplot> f(x) = 1<=x && x<=2 ? sin(x) : 2<= x && 3 ? 1/x : 1/0
gnuplot> plot f(x)
. x < 1 x > 3
, .
. .
gnuplot> f1(x) = 1<=x && x<=2 ? sin(x) : 1/0
gnuplot> f2(x) = 2<x && x<=3 ? 1/x : 1/0
gnuplot> plot f1(x) lt 1, f2(x) lt 1
.

21