Sie sind auf Seite 1von 8

SamyaBhattacharya

GNUplot Tutorials
Samya Bhattacharya1 B.E., M.Tech.

histutorialisofreadymadetype.Canbeusedasahandonreference.Itdescribesbasic andthensomecatchythings.ItworkswithgnuplotunderWindowstoo.Firstofall, executegnuplot.Gnuplotdisplaysabannerandcredit,andthenshowsagnuplotcommand lineprompt"gnuplot>".Gnuplotisacommandlinedrivenplottingtool.Yougivecommands heretomakeyourfigure. The"#"signisusedtocommentoutthelinefollowsit.Gnuplotinterpreterwillignorethe wholetextcommandafterthissign.Type"exit","quit"toclosegnuplotshell.Like: gnuplot>exit orgnuplot>quit .Type"help"forhelpregardinggnuplotthoughit maynot workunderwindowsenvironment.Onceyouquitgnuplot,allofsettingsyoumadewillbe lost. Tosavethecommandstocreateaplot,typeallthecommandssequentiallyinatextfile(with any extension .txtor.plt)andsavethefile.Orifthecommandsarealreadyexecuted in gnuplotthen,simplytype>save filename . To load the file containing commands for plotting, type >load filename or gnuplot filename directlyunderLinux. Toseethecurrentpathingnuplotuse pwd .Tochangetheworkingdirectorytypecd full path e.g.gnuplot>cd d:/samya/results (unixlike)or,gnuplot>cdd:\samya\results PlotCommand ot for2Dplotands plotf or3Dplot. pl SETLABELsofAXES: setxlabel MyAxeLabel tosetlabelofxaxis. setylabel MyWyeLabel tosetlabelofyaxis.Toinclude withinlabeluselike: setxlabel My\ foolish\ label SETrangeofaxes: setxrange[1:10] meansxaxisiscalibratedfrom1(initialvalue)to10(finalvalue)units. setyrange[10:100] meansyaxisiscalibratedfrom10(initialvalue)to100(finalvalue) units. TERMINALandOUTPUT Defaultterminaliswindow(forwindows)andx11(forlinux)andoutputisscreen,i.e.graph isshownonscreen.Itcanbecopypastedinotherapplications. Command tosettheterminalfor showing graphonscreenis >settermwindow or >set terminalwindow
1

Ph.D.ResearchScholar,DepartmentofElectricalEngineering,IITDelhi http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

Commandtosettheterminalaspostscript(outputtopsorepsfile)is>settermpostscript Tostorethepostscriptoutputinafileyouhavetosettheoutputfilename.Commandis: >setoutput filename.ps or,>setoutput filename.eps 2 Whenyouplottedthegraphonyourscreen,thefirstlinewasaredline.Howeveritturned intothesolidlinehere.Theblueandgreenlinesbecamethedashedlines.(Thoughitishard toseetheminasmallsizeimage.)Asyoucanseeabove,lineandsymboltypesdependonthe terminal you use. In order to know which line number corresponds to the solid, dashed, dotted,etc.trytest.Fore.g.: >settermx11 >test By shell commandwecanswitchtoshell(commandpromptincaseofWindowsorshellin caseofLinux)fromwithingnuplot.Type exit tocomeback. Toprintavariableingnuplot: >a=10 >printa Itgivesoutputtothescreenas10. Thereareseveralkeywordsandinbuiltconstantsingnuplotlike pi .Itsvalueisalready defined. DATAFILES Datafilesaresopreparedthat,valuesforanaxisarewrittensequentiallyinonecolumn. Anothercolumndenotesthesameforotheraxisandsoon.Eachsetofdatacorrespondsto onecolumn.Columnsareseparatedbyoneormorespaces.Columnsarenumberedas1for firstcolumn,2forsecondcolumnandsoon,internallybythegnuplot.So,byspecifyingthe numberofthecolumnandthekeywordus ing, setofdatacanbemapped(manytomany)to axes.Syntaxis: gnuplot>plot filename.dat usingx:ywithlines wherexandydenotecolumnnumbersforx andyaxis.Ifweusesplot(3Dgraph)thenthesamecanbewrittenasx:y:z gnuplot>plot numdata.dat using 1:2 with lines 1=>first column in x axis, 2=> second columninyaxis. LINESTYLE Astyleofgraphisspecifiedbythe with keyword.Intheexampleabove, lines styleis given,withwhicheachdatapointisconnectedbysmalllines.Thereareseveralkindsofline stylesthosearenumberedby1,2,3...Tochangethelinestyle,withlines isfollowedby thelinestylenumber.Ifthenumberisnotgiven,gnuplotassignsnumbersautomaticallyfrom 1toacertainmaximalnumber.

http://t16web.lanl.gov/Kawano/gnuplot/intro/basice.html http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

GraphWindowhasoptionforcopyingittoclipboard(pasteinMayuraDraw) MultiplePlots3 Toplotmultiplecurvesinonegraph,wecanwrite: gnuplot>plot filename1 using1:2withlines, filename2 using5:6withpoints Differentcolumnsofthesamefilecanalsobeplottedwherefilename1=filename2=abc.dat say.Multiplecommandsareseparatedbycomma. Whenalongcommandbecomesinevitable,breakthelinewithacharacter' thenextlineis \', regardedasacontinuousline.Don' tputanylettersafterthebackslash. e.g.:>plot filename using1:2withline,\ filename using1:3withlines,\ filename using1:6smoothcsplines

withlines drawthegraphwithstraightlinesbetweendatapoints.Ifwewantasmooth curve,wecanspecifyitwiththecommand smoothcsplinesa sabove. CURVETITLE Wecanuse titlec ommandforlegendsofthelines,e.g.: >plot filenameu sing1:2title blockinginfirstcellwit hlines bydefaultwithnotitlecommandspecified,f ilenameusing comesaslegend.Ifwedon t wantlegendofaspecificline,usethecommand notitle ortitle insteadoftitle.

http://t16web.lanl.gov/Kawano/gnuplot/intro/plotcalce.html http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

GRAPHTITLE Titleofthewholegraphcanbesetthrough>settitle TitleoftheGraph2,3 Where2,3providesthex&ycoordinateofthefirstletterofthetitletextw.r.t.theleftandtop lineofthegraph.Defaultis0,0(centeraligned). Toavoidretypinglongplottingcommandforreplottingthelastplottedgraph,use >replot AXESGRADUATION Tochangethexaxisgraduation>setxtics0.5 where0.5denotesgraduationwith0.5interval (increment). >setxtics1,0.5 means1isthestartvalueand0.5istheincrement. >setxtics1,0.5,7 means1isthestartvalue,0.5istheincrementand7istheendvalue. Similarly>setytics0,10,100 foryaxis Forminortics(graduation)inbetween: >setmxtics3 where3denotesthenumberofpartitionsinbetweentwoconsecutiveticsofx axis.Similarly,>setmytics5 foryaxis. DATAFILE4 Inadatafiletwoblanklinesseparateeachdatablock.Toaccesseachdatablockinthedata file,usetheindexkeywordtospecifytheblocktobereferred.Youcanspecifythefirstblock by index0:0 or index0.Thethirdblockispointedby index2.Tocombinethefirstand secondblocks,useindex0:1.Fore.g.: >plot filename.dati ndex0:1using1:2smoothbezier Shortnames Gnuplotrecognizesshortkeywords,forexample w is with , i is index, andsoon.In addition,youcanomitafilenameifthesamefileisused,justliketheexampleabove.Inthe nexttwolinesafterthefirst plot commandline,ashortform canbeusedinsteadof filename.dat. PlotFunction >plotf(x)withlines Fore.g.: >f(x)=x**2 >plotf(x)smoothcsplines mathematicaloperatorsarelikegnuoctave5. LineStyles Commandis>setstyleline1lt2lw3 whichsetsthestyleofalinemarkedas linestyle1 .lt denotes line type(varies from 1to 21,checkwithset term andtest command) and lw denoteslinewidth(variesfrom1to6).Themarkercanbeusedinaplottingcommandtoset allthestyledefinedabovelike>plot"tut2.dat"using1:6title"blockingprob.forC=12"with lineslinestyle1 fore.g.: >setstyleline2lt1lw2
4 5

http://t16web.lanl.gov/Kawano/gnuplot/intro/plotexpe.html http://www.fi.uib.no/Fysisk/Teori/nyoctave.html http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

>setstyleline3pt4ps5 >plot"tut2.dat"using1:7notitlesmoothcsplineslinestyle2 lt=>linetype,lw=>linewidth,pt=>pointtype,ps=>pointsizecheckwithtest Logscale setlogscalex commandsetthexaxisinlogscale.Similarlyforyaxis>setlogscaley . ShowGrid Toshowgridinthegraphcommandis,>setgrid .Gridisshownatthemajortics. Functions6 DefinitionofafunctionissimilartoFortranorCprogramminglanguage.Intheexample below,f(x)=c/((xa)*(xa)+b)+d/sqrt(x)definesourequation.Squareof(xa)termalsocanbe writteninaFortranmanner,(xa)**2.Theparameters,a,b,c,anddarearbitrary. gnuplot>a=0.25 gnuplot>b=0.02 gnuplot>c=0.05 gnuplot>d=0.1 gnuplot>f(x)=c/((xa)*(xa)+b)+d/sqrt(x) gnuplot>setxrange[0:1] gnuplot>setyrange[0:4] gnuplot>plotf(x) Table Toobtainthecalculatedvaluesinatabulatedformat,whichcanbeprocessedwithother applicationssuchasaspreadsheet,useaspecialterminaltable.Towritetheresult,specifya filenamewithsetoutput. >settermtable >setoutput"table6.txt" >setstyleline1lt2lw3 >setstyleline2lt6ps4pt9 >plot"tut2.dat"using1:6title"blockingprob.forC=12"withlinelinestyle1,\ "tut2.dat"using1:7notitlewithpointslinestyle2,\ "tut2.dat"using1:8title""smoothcsplines Outputinthetable6.txtlookslike: #Curve0,4points #xytype 10.741i 30.698i 50.626i 70.493i #Curve1,4points
6

http://t16web.lanl.gov/Kawano/gnuplot/intro/plotfunce.html http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

#xytype 10.758i 30.647i 50.44i 70.272i #Curve2,100points #xytype 10.746i 1.060610.741064i 1.121210.736123i 1.181820.731174i 1.242420.72621i 1.303030.721229i 1.363640.716225i 1.424240.711194i 1.484850.706131i 1.545450.701031i LeastSquareFitting Itisquiteeasytodoaleastsquaresfittingwithgnuplot.Justusethefit command,andadd parameterstobesearchedforbythevia option.Whenyourfittingfunctionisstronglynon linear,youneedtobecarefulabouttheinitialvaluesofyourparameters. #plotequationandexperimentaldata settermwindow setxlabel"servicerate[calls/sec]" setylabel"blockingprobability" setxrange[1:7] setyrange[0:1] setxtics0.5 setytics0.1 a=0.7 b=0.25 c=1.5 f(x)=ab*x**c/7**c plotf(x)title"FittedProb.",\ "tut2.dat"using1:6title"ExperimentalProb."smoothcsplines pause1"ProceedforLeastSquarefit?" #LeastSquareFit fitf(x)"tut2.dat"using1:6viaa,b,c pause1"Replotthegraphwithmodifiedparameters?" load"tut8b.txt"

http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

#plotfromleastsquarefit settermwindow setgrid setxlabel"servicerate[calls/sec]" setylabel"blockingprobability" setxrange[1:7] setyrange[0:1] setxtics0.5 setytics0.1 a=0.742541 b=0.248545 c=2.16153 f(x)=ab*x**c/7**c plotf(x)title"FittedProb.",\ "tut2.dat"using1:6title"ExperimentalProb."smoothcsplines PauseCommand7 Pausecommandstopstheexecutionandaskusertoproceedornot.Syntaxis: >pause1Y ourmessage
1 0 .9 b lo c k in g p ro b a b ility 0 .8 0 .7 0 .6 0 .5 0 .4 0 .3 0 .2 0 .1 0 1 1 .5 2 2 .5 3 3 .5 4 4 .5 5 5 .5 s e rv ic e ra te [c a lls /s e c] 6 6 .5 7 F itte d P ro b . E x p e rim e n ta l P ro b .

FigureforLaTeX Togeneratefigureforlatexbothinepsandpdfformatuse: >settermpostscriptepsenhancedcolor or, >settermpostscripteps >setoutput figurename.eps epsfigureisreadytoincludeinlatexdviordvitops.Thenconvertepsfiguretopdfwith AdobeAcrobat(Windows)orps2pdf(linux)andyourpdffigureisreadyforlatexpdf.

http://t16web.lanl.gov/Kawano/gnuplot/spherical_harmonics/deformede.html http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

SamyaBhattacharya

BatchMode8 Writeallcommandssequentiallyinafileandloadthefilecreatesabatchprocesstodraw graph. It is convenient because the file is a text file can be edited accordingly. Also, considerableeffortwillbesavedretypingcommands. A commandline option persist also keeps the graph on your screen. With this method, gnuplotitselfexitsbutthegraphwindowsettlesdown. gnuplotpersistoutput.plt DifferentPlotStyles9 Lines:Itconnectseachdatapointwithlines.Forsmoothcurveuse smoothcsplines. Dots:Itdisplaysdots,canbeusedwhentherearemanydatapoints,buthardtoseethough. Points:Symbolicpointsareshownatdatapoints.Canbeusedforfiniteexperimentaldata. Pointtypeandsizecanbespecifiedusingpt(orpointsize)andps(pointsize)commands respectively.10

8 9

http://t16web.lanl.gov/Kawano/gnuplot/intro/workinge.html http://t16web.lanl.gov/Kawano/gnuplot/intro/stylee.html 10 Foreachofthesestyles,smootheningcanbedoneusing>plot title smoothcsplineswithpoints http://t16web.lanl.gov/Kawano/gnuplot/intro/indexe.html

Das könnte Ihnen auch gefallen