Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 A Portable Scientific Visualization Program: GnuPlot Asst. Prof. Emin Korkut.

Similar presentations


Presentation on theme: "1 A Portable Scientific Visualization Program: GnuPlot Asst. Prof. Emin Korkut."— Presentation transcript:

1 1 A Portable Scientific Visualization Program: GnuPlot Asst. Prof. Emin Korkut

2 2 GNUPlot is an interactive function plotting program. It has interactive or batch modes. To invoke interactive mode it is sufficient to give the gnuplot command at the command prompt of linux. When this is done a prompt appears and prompts the user to give gnuplot commands. The commands of gnuplot may need parameters and arguments depending on what you want them to do. Gnuplot syntax is case sensitive. You can abbreviate the command names as long as the abbreviation is not ambiguous. Any number of commands may appear on a line, separated by semicolons (;). Strings are indicated with quotes. They may be either single or double quotation marks. You may extend the gnuplot commands over several input lines but for this purpose you must end each line except the last one with a backslash (\). The backslash must be the last character on each line.

3 3 Now we can start to plot functions. First we deal with the library functions and their combinations. Consider the following command gnuplot>plot sin(x)

4 4 As can be seen the display range is selected between -10 and 10 for the x axis and between -1 and 1 for the y axis. These are default values for the plotting range of the sine function. The default plotting range in vertical direction may vary depending on the function. Whereas the horizontal default range is always between -10 and 10. The default ranges can be changed by the user. For example plot [-5:5] sin(x) command selects the horizontal plotting range between -5 and 5. The specification of the horizontal range needs two numerical values for the beginning and the end points. They must be separated by colon and enclosed by the brackets. One or both of the numerical values can be skipped. In that case either left or right side of the colon will include nothing. If both of the numerical values is not given then inside of the brackets contains nothing. The display output of this command is given below

5 5

6 6 The ticks on the horizontal axis for this plot are positioned by gnuplot which has used an interval whose length equals 2 between ticks. This can be changed. For this we can modify the last example as follows set xticks 1 plot [-5:5] sin(x) where the interval between two consecutive ticks is set to 1. The resulting display is as follows.

7 7

8 8 The range for the vertical coordinates can also be set by the user. For this purpose we can use an additional pair of brackets. For example, the command plot [-5:5] [-2:2] sin(x) produces the following display output.

9 9 On the other hand the vertical tics can be controlled by using the set ytics command as done in the following sample command. set ytics 1 plot [-5:5] [-2:2] sin(x)

10 10 It is possible to plot more than one function at a single attempt. For this purpose the functions to be plotted must be given in comma separated form like the following command. set xtics 1; set ytics 1 plot [-5:5] [-2:2] sin(x), cos(x), tan(x) This plots the trigonometric functions, sine, cosine, and tangent and produces the following display output.

11 11

12 12 Comment In GNUPlot comments are created by using the character \#. This symbol can be positioned at the beginning of or somewhere else in a line. GNUPlot ignores the remaining portion of the line after this character. The effect of this character vanish between quotation marks, inside numbers and inside command substitutions. As a matter of fact it is alive anywhere it makes sense to work. Exit The commands exit and quit and the END-OF-FILE character exit GNUPlot. All these commands clear the output device before exiting.

13 13 Functions The functions in GNUPlot are the same as the corresponding functions in the Unix mathematics library, except that all functions accept integer, real, and complex arguments, unless otherwise noted. The sgn function is also supported, as in BASIC. * abs: The abs function returns the absolute value of its argument. The returned value is of the same type as the argument. For complex arguments, abs(x) is defined as the length of x in the complex plane [i.e., sqrt(real(x)**2 + imag(x)**2) ]. * acos: The acos function returns the arc cosine (inverse cosine) of its argument. acos returns its argument in radians. * arg: The arg function returns the phase of a complex number, in radians.

14 14 * asin: The asin function returns the arc sin (inverse sin) of its argument. asin returns its argument in radians. * tan: The atan function returns the arc tangent (inverse tangent) of its argument. atan returns its argument in radians. * ceil: The ceil function returns the smallest integer that is not less than its argument. For complex numbers, ceil returns the smallest integer not less than the real part of its argument. * cos: The cos function returns the cosine of its argument. cos expects its argument to be in radians. * cosh: The cosh function returns the hyperbolic cosine of its argument. * exp: The exp function returns the exponential function of its argument (e raised to the power of its argument).

15 15 * floor: The floor function returns the largest integer not greater than its argument. For complex numbers, floor returns the largest integer not greater than the real part of its argument. * imag: The imag function returns the imaginary part of its argument as a real number. * int: The int function returns the integer part of its argument, truncated toward zero. * log: The log function returns the natural logarithm (base e) of its argument. * log10: The log10 function returns the logarithm (base 10) of its argument. * real The real function returns the real part of its argument.

16 16 * sgn: The sgn function returns 1 if its argument is positive, -1 if its argument is negative, and 0 if its argument is 0. If the argument is a complex value, the imaginary component is ignored. * sin: The sin function returns the sine of its argument. sin expects its argument to be in radians. * sinh: The sinh function returns the hyperbolic sine of its argument. * sqrt: The sqrt function returns the square root of its argument. * tan: The tan function returns the tangent of its argument. tan expects its argument to be in radians. * tanh: The tanh function returns the hyperbolic tangent of its argument.

17 17 Operators The operators in GNUPlot are the same as the corresponding operators in the C programming language, except that all operators accept integer, real, and complex arguments, unless otherwise noted. The ** operator (exponentiation) is supported, as in FORTRAN. Parentheses may be used to change order of evaluation. The following is a list of all the binary operators and their usages:

18 18 *a*bmultiplication /a/bdivision % a%bmodulo +a+baddition -a-bsubtraction = a = = bequality ! =a! = binequality & a & & blogical AND | |a | | blogical OR where the factorial operator returns a real number to allow a greater range.

19 19 Help The help command displays on-line help. Load The load command executes each line of the specified input file as if it had been typed in interactively. Files created by the save command can later be loaded. Any text file containing valid commands can be created and then executed by the load command. Files being loaded may themselves contain load commands. The load command must be the last command on the line. The syntax of the command is load "inputfile". The name of the input file must be enclosed in (either single or double) quotes. The load command is performed implicitly on any file names given as arguments to GNUPlot. These are loaded in the order specified, and then GNUPlot exits.

20 20 plot [-20:20] sin(x), atan(x), cos(atan(x))

21 21 plot [-20:20] sin(30*x)*atan(x)

22 22 set parametric set dummy t set autoscale set title “t, sin(t)/t or sin(x)/x” plot t, sin(t)/t

23 23 set parametric set dummy t set autoscale set title “” plot sin(t)/t, t

24 24 set parametric set dummy t set autoscale set samples 160 set title “” plot sin(t), cos(t)

25 25 set parametric set dummy t set autoscale set xrange [-3:3] set yrange [-3:3] set title “Parametric conic sections” plot –t, t, cos(t), cos(2*t), 2*cos(t), sin(t), -cosh(t), sinh(t) set title “”

26 26 set parametric set dummy t set autoscale set xrange [-5:5] set yrange [-5:5] plot tan(t), t, t, tan(t)

27 27 set parametric set dummy t set autoscale set trange [0.00001:3] plot t, log(t), -t, log(t), sin(t), t**2, -sin(t), t**2

28 28 set parametric set dummy t set autoscale set yrange [-1.5:1.5] set trange [0.0001:10*pi] plot sin(t)/t, cos(t)/t

29 29 set noborder set clip set polar set autoscale set xtics axis nomirror set ytics axis nomirror set zeroaxis set trange [0:2*pi] set title “Three circles (with aspect ratio distortion)” plot.5,1,1.5

30 30 set noborder set clip; set polar set xtics axis nomirror; set ytics axis nomirror set samples 160; set zeroaxis set trange [0:2*pi] set title “” plot cos(2*t)

31 31 set noborder set clip; set polar set xtics axis nomirror; set ytics axis nomirror set samples 160; set zeroaxis set trange [0:2*pi] set title “” plot 2*sqrt(cos(t)), -2*sqrt(cos(t))

32 32 set noborder set clip; set polar set xtics axis nomirror; set ytics axis nomirror set samples 160; set zeroaxis set trange [0:2*pi] plot sin(4*t), cos(4*t)

33 33 set samples 21; set isosamples 11 set xlabel “X axis” –3,-2; set ylabel “Y axis” 3,-2 set zlabel “Z axis” -5; set title “3D gnuplot demo” set label 1 “This is the surface boundary” at –10,-5,150 center set arrow 1 from –10,-5,120 to –10,0,0 nohead set arrow 2 from –10,-5,120 to 10,0,0 nohead set arrow 3 from –10,-5,120 to 0,10,0 nohead set arrow 4 from –10,-5,120 to 0,-10,0 nohead set xrange [-10:10]; set yrange [-10,10] splot x*y

34 34 set samples 21; set isosamples 11 set xrange [-10:10]; set yrange [-10,10] set grid splot x**2+y**2, x**2-y**2

35 35 set samples 21; set isosamples 11 set xrange [-10:10]; set yrange [-10,10] set ticslevel 0.0 set title “3D gnuplot demo (ticslevel = 0.0)” splot (x**3+y**3)/10

36 36 set samples 21; set isosamples 11 set xrange [-10:10]; set yrange [-10,10] set ticslevel 2.0 set title “3D gnuplot demo (ticslevel = 2.0)” splot (x**3+y**3)/10

37 37 set samples 21; set isosamples 11 set xrange [-10:10]; set yrange [-10,10] set grid set ticslevel 0.5 set title “3D gnuplot demo (ticslevel = 0.5)” splot (x**3+y**3)/10

38 38 set samples 21; set isosamples 11 set xrange [-10:10]; set yrange [-10,10] splot x*y with points

39 39 set xtics autofreq set ytics autofreq set xrange [-1:1]; set yrange [-1,1] set samples 51; set isosample 21 set dummy u,v; set title “3D gnuplot demo” splot u*v / (u**2+v**2+0.1)


Download ppt "1 A Portable Scientific Visualization Program: GnuPlot Asst. Prof. Emin Korkut."

Similar presentations


Ads by Google