1 / 15

Gnuplot Introduction

Gnuplot Introduction. CSE 4251 Instructor: Dong Li li.1011@osu.edu. What is G nuplot. A portable command-line driven graphing utility for Linux/Windows/.... can output most of the picture formats eps / pdf / tex : good for writing academic pictures

beck
Télécharger la présentation

Gnuplot Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gnuplot Introduction CSE 4251 Instructor: Dong Li li.1011@osu.edu

  2. What is Gnuplot • A portable command-line driven graphing utility for Linux/Windows/.... • 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 %gnuplot gnuplot> plot sin(x) gnuplot> gnuplot > set xrange [0:5] gnuplot > replot

  4. commonly use 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 page • show [all] # show (all) the settings • plot #primary command for drawing figures. • plot sin(x) • plot ‘filename’ using 2:3 with linespointslinetype 1 pointtype 2 title ‘Figure’ • plot ‘filename’ u 2:3 w lplt 1 pt 2 t ‘figure’ #same meaning as above

  5. plot in script %cat sin.plt plot sin(x) #picture disappears without pause, use ‘help pause’ in gnuplot terminal to learn more. pause -1

  6. save plot to a file • define plot terminal • set terminal png #save to png format picture • set output ‘output.png’ #specify the output picture • may other options for different terminals: background color, canvas size, line type, may vary with terminal type • What I often use to plot figures in paper: set terminal postscript eps enhanced monochrome explain: ‘postscriteps’: create .eps figure for latex ‘enhanced’ : allow enhanced text features : subscripts, superscripts, etc. ‘monochrome’: use gray scale color, change to ‘color’ if you want to use color

  7. plot functions • plot – 2D figure, splot – 3D figure • built-in functions: sin, cos, exp, log, log10, sqrt, norm, abs, etc. • define your own function: +, - , *, / , ** • f(x)=5*x**2+1 plot f(x) • plot 3*x+5*sin(x) • splot sin(x)+sin(y)#3D plot

  8. plot text • set title “A Figure” #set the title of the figure • set xlabel “time” #set the x-axis label as time • plot .... title “data 1” # set the legend in a figure • set label 1 “This is {/Symbol p}” at 3.14, 0 #use the x-y coordinate in the plot, use Greek letter for pi • set label 2 “This is a label” #specify the position later • set label 2 at graph 0,0 #using graph coordinate left, bottom of the picture

  9. plot shapes rectangle/ellipse/circle/polygon/arrow • set object 1 rect from 0,0 to 1,4 fc rgb ‘yellow’ fs solid pattern 2 explain: draw rectangle, fc: fill color, fs : fill style fill with yellow colored pattern, pattern type is 2 • set object 2 circle center 2,2, size 1 arc [10:50] explain: draw an arc from 100 to 500, with center (2,2) and radius is 1. • set arrow 1 from 1,1 to 1,2 #arrow from (1,1) to (1,2) • set arrow 2 from 1,1 rto 1,2 #relative position, arrwo from (1,1) to (2,3) • see ‘help polgyon’, ‘help ellipse’

  10. plot data %cat datafile 3.0 .98 3 4 5.3 .97 5 23 2.7 .8 2 18 5.1 .95 4 15 4.0 .7 4 17 4.4 .84 5 20 5.1 .94 3 13 4.5 .89 5 9 5.7 .94 5 1 set datafile separator ‘,’ # if you use “,” to separate fields file=“datafile” set pointsize 2 plot file using 1:2 with points pt 1 #plot using the first and the second column in datafile #you can modify the column data with arithmetic or functions plot file using 1:($2*2) with points pt 2 #plot using the first column and the second column times 2 plot file using 1:(f($2)) with point pt 3 #call function f and apply to column 2

  11. plot range • set xrange [0:5] #define x range • set yrange [0:10] # define y range • plot [0:5][0:10]norm(x) #plot normal distribution function in xrange [0:5], yrange[0:10]

  12. multiplot • plot several figures on the same canvas • plot f1(x), f2(x), ... # put all the plot commands in a sequence • plot f1(x)\n plot f2(x) #use several plot commands dose not work well • Multiplot • set multiplot, unset multiplot • can use several plot commands in multiplot environment • set multiplot layout <rows>, <cols>

  13. Multiplot example #plot side-by-side set multiplot layout 1,2 plot sin(x) plot cos(x) unset multiplot

  14. Decorate your figures • Gnuplot supports hundreds of plot styles %cat measure 1 9 0.2 -0.5 2 11 0.1 -0.4 3 13 0.2 -0.2 4 13.5 1.0 -0.4 5 14 0.1,-0.2 6 16 0.6,-0.7 try the following plot commands set style fill transparent solid 0.2 noborder plot ‘measure' using 1:2:(abs($3)+abs($4)) with circles, ‘measure' using 1:2 with linespoints plot ‘measure’ u 1:2 with histeps plot ‘measure’ u 1:2 with boxes plot ‘measure’ u 1:2:($3*10) with filledcu plot ‘measure’ u 1:2:($2+$3):($2+$4) with yerrorbars, ‘measure’ using 1:2 with boxes

  15. References Find the demos , tutorials and documents at http://www.gnuplot.info/, Visualize your data with gnuplothttp://www.ibm.com/developerworks/linux/library/l-gnuplot/ Display data on webpages http://www.ibm.com/developerworks/aix/library/au-gnuplot/index.html

More Related