Download presentation
1
CSE4251 The Unix Programming Environment
Lecture 13 gnuplot
2
What is Gnuplot A portable command-line driven graphing utility
can output most of the picture formats eps/pdf/tex: good for writing academic pictures now added html, javascript: display data on web Can use interactive command and script file script is good to automate the task!
3
Interactive plot launch gnuplot: $ gnuplot $ gnuplot gnuplot>
gnuplot> plot sin(x)
4
set plot range set xrange [0:5] # define x range
set yrange [0:10] # define y range $ gnuplot gnuplot> gnuplot> plot sin(x) gnuplot > set xrange [0:5] gnuplot > replot
5
plot from script Save plot commands in file, and run gnuplot:
$ gnuplot mycmds.plt Output disappears quickly; use pause to see the result, e.g.: plot sin(x) pause -1 "Hit any key to continue“
6
commonly used commands
help topic #get help about a topic replot #repeat last plot command clear #remove objects in the canvas set OPTION [VALUE] #specify plot options set xrange [0:5] #set the horizontal axis range set multiplot #several plots on the same figure show [all] # show (all) the settings plot #primary command for drawing 2 D figures. plot sin(x) plot ‘datafilename’ using 2:3 with linespoints linetype 1 pointtype 2 title ‘MyFigure’ plot ‘datafilename’ u 2:3 w lp lt 1 pt 2 t ‘MyFigure’ #same meaning as above splot #drawing 3D figures.
7
save plot to a file Define terminal type and file name
set terminal png #set terminal to png type #allow creating png format picture set output ‘output.png’ #specify the name of the output file #figure will be saved to the file #instead of be displayed on the screen
8
plot functions built-in functions define your own function
sin, cos, exp, log, log10, sqrt, norm, abs, etc. define your own function +, - , * , / , etc.
9
plot functions Examples gnuplot> f(x)=5*x*2+1 gnuplot> plot f(x)
10
plot functions Examples gnuplot> plot 3*x+5*sin(x)
11
plot functions Examples gnuplot> splot sin(x)+sin(y)
12
add text to plot set title “A Figure” #set the title of the figure
set xlabel “time” #set the x-axis label as time set label 1 “This is a label1” #specify the name of a label set label 1 at graph 0,0 #specify location of label 1, using graph coordinate #0,0 is bottom left and 1,1 is top right set label 2 “This is label2” at 3.14, 0 #place the label at a particular x-y coordinate
13
add shape to plot gnuplot> set object 1 rect from 0,0 to 1,4
gnuplot> plot [-5:5] x, -3+sin(x*5)/x lt 3 lw 3
14
plot data file datafile plot script # using 1:2
$ cat plotdata.txt datafile="./plotdata.txt" set terminal png set output "points.png" plot datafile using 1:2 with points pause -1 "Hit any key to continue” # using 1:2 # use the 1st and 2nd columns # with points # use points to plot data
15
plot data file result
16
plot data file plot with connected points
datafile="./plotdata.txt" set terminal png set output “linespoints.png" plot datafile using 1:2 with linespoints pause -1 "Hit any key to continue”
17
plot data file result
18
plot data file plot with all three columns
datafile="./plotdata.txt" set terminal png set output “linespoints.png" splot datafile using 1:2:3 with linespoints pause -1 "Hit any key to continue”
19
plot data file result
20
multiplot plot in the same figure
plot f1(x), f2(x), ... Multiplot: plot in multiple subfigures set multiplot layout <rows>, <cols> unset multiplot
21
multiplot example gnuplot> set multiplot layout 1,2
multiplot> plot sin(x) multiplot> plot cos(x) multiplot> unset multiplot
22
References Find the demos , tutorials and documents at Visualize your data with gnuplot Display data on webpages
23
Labs Lab 4 DUE: 11:59pm, Tuesday, April 14, 2015 Lab 5 DUE: 11:59pm, Tuesday, April 28, 2015 (Late submission will not be accepted )
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.