Sie sind auf Seite 1von 6

=Plotting2Dgraphs= WelcometothespokentutorialonPlotting2Dgraphswithscilab. AssumingthatScilabisinstalledonyourcomputer,wewilldiscussplotsinScilab. Scilaboffersmanywaystocreateandcustomizevarioustypesof2Dand3Dplots. TheseveralcommonchartsthatScilabcancreateare:xyplots,contourplots,3Dplots,histograms,bar charts,etc... NowopenyourScilabconsolewindow.IwillusePlotting.scefiletocutandpastethecommands. InordertoPlot,weneedasetofpoints.Letuscreateasequenceofequallyspacedpoints.Thiscanbe donebythelinspacecommandwhichcreatesalinearlyequallyspacedvector. ForExample >x=linspace(1,10,5) xisarowvectorwith5pointswithlinearlyequallyspacedbetweenpoints1and10 Similarlyyisarowvectorwithlinearlyequallyspaced5pointsbetweenpoints1and20 >y=linspace(1,20,5); MoreinformationonlinspacecommandcanbeobtainedfromtheHelpdocumentation.

WewillnowwewillplotagraphwiththeargumentsxandyusingthePlotfunction.Thisissimilartothe oneusedinmatlab. >plot(x,y) createsagraphofxversesyasyousee. Noticethatthegraphicswindowislabeledas'0' Wewillopenanothergraphicwindowusingthe xset('window',1) function.Iwillclosethiscutthexsetfunctionpasteinscilabhitenter. Youwillseeagraphicwindownumber1.Notethattwoargumentsarepassedtothisfunctionnamely thewindowand1. Thenextgraphwillbeplottedonthiswindow. Forscilabplot2disthenativefunctionusedtoplot2dgraphs.

>plot2d(x,y,style=3) plot2dcommandplotagraphofxversesyasyousee. Noticethatthereisathirdargumentcalledstyle.Styleargumentisoptional.Itisusedtocustomizethe appearanceoftheplot. Forpositivevaluesofstylethecurveisaplainlinewithdifferentcolourslikegreenfor3inourcase.The defaultvalueofstyleis1.Tryplottinggraphsfornegativevaluesandseethedifferenceinappearance foryourself. Alsowecansetthestartpointsandendpointsforxandyaxisbypassingthefourthargument.Itis calledrect. >plot2d(x,y,style=3,rect=[1,1,10,20]) Wehavexaxisstartingfrom1to10andyaxisfrom1to20. Theorderofargumentintherectcommandisxmin,ymin,xmaxandymax. LetusnowlearnaboutTitle,AxisandLegends Toconfigurelabelstotheaxisandtitleoftheplotwecanusethecommands >title("Mytitle") >xlabel("X");and >ylabel("Y"); Iwillcutthissetofcommandsandpasteintheconsole. Youwillseethatthegraphhasbeenlabeledxtothexaxis,ytotheyaxisandtitleofthegraphismy title. Youmaywanttoconfigurethetitleandaxisoftheplotinasinglecommandinsteadof3forthis purposeweusethextitle >xtitle("Mytitle","Xaxis","Yaxis"); commandforallthe3arguments.Iwillcutthiscommandpasteinscilabandhitenter.Nowyouseethat thexaxislabelisXaxis,YaxisandthetitleisMytitle. Theclf()functionthatiamtypingnowwillclearthegraphicwindowasyousee. Itisusefulwhileplottingdifferentgraphonthesamegraphicwindow.

Iwillclosethiswindow. Sometimesweneedtocomparetwosetsofdatainthesame2Dplot,thatis,onesetofxdataandtwo setsofydata. Letusseeanexampleforthis Iwillscrolldown Wewilldefinethexaxispointsinarowvectorxusingthelinspacecommand Letusdefineafunction y1=x^2 plotxversesy1 defineanotherfunction y2=2*x^2 plotxversesy2 wewillalsogivelabelandtitletoourgraph Noticethatwehaveadditionallypassedtheoand+commandstotheplotfunction,tochangethe appearanceofthecurve >x=linspace(1,10,50); >y1=x^2; >plot(x,y1,"o") >y2=2*x^2; >plot(x,y2,"+") >xtitle("Mytitle","Xaxis","Yaxis"); Theseargumentsarenotapartoftheplot2dfunction.Theycanbeusedonlywiththeplotfunction Iwillcopythesesetofcommandsandpasteinthescilabconsole Youseethegraph Wouldn'titbeofgreathelptoknowwhichcurveisassociatedwithwhichfunction? Thiscanbeachievedusingthelegendcommandasyousee

>legend("x^2","2*x^2"); "o"curverepresentsfunctiony1=x^2functionand"+"curverepresentsfunctiony2=2*x^2 Iwillclosethisgraphicwindow [[File:title.jpeg]] Wewillnowdiscussaboutplot2ddemosandsubplotfunction Scilabprovidesdemosforallitsmajorfunctions Demosofplot2dcanbeviewedthroughdemonstrationtabclickonGraphics,clickplot2d_3dplotsand selectademooutthevariousdemosprovided.Iwillclickonplot2d. Youwillseethedemograph Thecodeforthisgraphcanalsobeseenbyclickingtheviewcodebutton. ThislinkdoesnotopeninMacOSbutworksinwindowsandlinux NeverthelessinMacthecodecanbeviewedthroughthedirectory. Letusgototheterminal. currentlyiamindemosdirectoryofscilab5.2 Thefullpathtothisdirectoryisshownhere. wewilltype ls toseethelistofdemosavailableasyouseehere. thenwewillselectthe2d_3d_plotsdirectoryandhitenter typelsagaintoseevariousdemocodeavailableinthescefiles ls wewillviewthecodeforthedemowhichwehaveseenearliertype moreplot2d.dem.sce andhitenter. Hereyouwillseethecodeforthedemographofplot2dfunction Iwillclosetheterminal

Iwillclosethedemographandthedemoswindow Similarlyyoucangothroughtheotherdemosandexplorescilab LetusnowdiscussaboutSubplotfunction Thesubplot()functiondividesagraphicswindowintoamatrixofsubwindows. Toexplainthisfunctionwewillusedemosforplotting2Dgraphsinscilab. foreg.type >plot2d() ontourconsoleandseethedemoplotforthisfunction [[File:plot2d.jpg]] Iwillclosethiswindow. Thesubplotcommandbreaksthegraphicswindowintoa2by2matrixofsubwindowsrepresentedby thefirsttwoargumentsinthesubplotcommandthethirdargumentdenotesthecurrentwindowin whichtheplotwillbeplotted Iwillexecutethiswholesetofcommandsbycopyinginthescilabconsole >subplot(221) >plot2d() >subplot(222) >plot2d2() >subplot(2,2,3) >plot2d3() >subplot(2,2,4) >plot2d4() [[File:subplot2.GIF]] Youcansee4plotsonasingleplotwindow Theplotobtainedcanbesavedasaimageonyourcomputer.Clickonthegraphicwindow,gotoFile menuselectexporttooption.

Giveasuitabletitletoyourplot,selectadestinationfoldertosaveyourfileselectthefileformatin whichyouwantyourimagetoappear. IwillselecttheJPEGformatandClickSave. Browsethroughthedirectorytoopentheimageandverifyyourselfwhetherithasbeensavedornot. ThisbringsustotheendofthisspokentutorialonPlotting2DgraphsusingScilab.Therearemanyother functionsinScilabwhichwillbecoveredinotherspokentutorials.KeepwatchingtheScilablinks. SpokenTutorialsarepartoftheTalktoaTeacherproject,supportedbytheNationalMissionon EducationthroughICT.Moreinformationonthesameisavailableathttp://spoken tutorial.org/NMEICTIntro. Thanksforjoining.Goodbye.

Das könnte Ihnen auch gefallen