>> %Create some x & y data to play with >> x=linspace(0,1,50); >> y=sin(2*pi*x*2)./(2*x+0.5); >> >> %Plot y=f(x) with defaults: >> plot(x,y); >> >> %Plot y letting Matlab choose x >> plot(y);%Note how x-axis changes from [0 1] to [1 50] >> >> %Plot as red-dashed line with circels at points >> plot(x,y,'ro:') >> >> %Get other plot options from help >> help plot PLOT Linear plot. PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted. PLOT(Y) plots the columns of Y versus their index. If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)). In all other uses of PLOT, the imaginary part is ignored. Various line types, plot symbols and colors may be obtained with PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 columns: b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star y yellow s square k black d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line. PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings. For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points. The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property. PLOT returns a column vector of handles to LINE objects, one handle per line. The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines. See also SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, GRID, CLF, CLC, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM. Overloaded methods help cfit/plot.m help fints/plot.m help ntree/plot.m help dtree/plot.m help wvtree/plot.m help rwvtree/plot.m help edwttree/plot.m >> >> >> %Plot again, but save handle >> h=plot(x,y) h = 102.0015 >> %Note that h is just a number >> >> %Get the properties of h >> get(h) Color = [0 0 1] EraseMode = normal LineStyle = - LineWidth = [0.5] Marker = none MarkerSize = [6] MarkerEdgeColor = auto MarkerFaceColor = none XData = [ (1 by 50) double array] YData = [ (1 by 50) double array] ZData = [] BeingDeleted = off ButtonDownFcn = Children = [] Clipping = on CreateFcn = DeleteFcn = BusyAction = queue HandleVisibility = on HitTest = on Interruptible = on Parent = [101.001] Selected = off SelectionHighlight = on Tag = Type = line UIContextMenu = [] UserData = [] Visible = on >> >> %Get the properties and their options with set >> set(h) Color EraseMode: [ {normal} | background | xor | none ] LineStyle: [ {-} | -- | : | -. | none ] LineWidth Marker: [ + | o | * | . | x | square | diamond | v | ^ | > | < | pentagram | hexagram | {none} ] MarkerSize MarkerEdgeColor: [ none | {auto} ] -or- a ColorSpec. MarkerFaceColor: [ {none} | auto ] -or- a ColorSpec. XData YData ZData ButtonDownFcn: string -or- function handle -or- cell array Children Clipping: [ {on} | off ] CreateFcn: string -or- function handle -or- cell array DeleteFcn: string -or- function handle -or- cell array BusyAction: [ {queue} | cancel ] HandleVisibility: [ {on} | callback | off ] HitTest: [ {on} | off ] Interruptible: [ {on} | off ] Parent Selected: [ on | off ] SelectionHighlight: [ {on} | off ] Tag UIContextMenu UserData Visible: [ {on} | off ] >> %Note: defaults are in braces >> >> %Let's change h to a red line with big, blue circles outlined in black >> set(h,'color','r','marker','o','markerfacecolor','b','markeredgecolor','k','markersize',6) >> >> >> %Now for the example >> %First, generate the data with AdvDiff1D >> %This is a function which implements advection-diffusion in dimension >> %with periodic BC's >> [x,t,N]=AdvDiff1D(10,-1,0.1, 10, 12, 0.5, 0.25); sigma=0.1, lambda=0.5 >> %List variables to see what we've got >> whos Name Size Bytes Class N 19x49 7448 double array ans 1x70 140 char array h 1x1 8 double array t 1x49 392 double array x 19x1 152 double array y 1x50 400 double array Grand total is 1120 elements using 8540 bytes >> %N, the data has 19 rows (one for each x location), >> % and 49 columns (one for each time); >> %Let's plot the first time >> plot(x,N(:,1)) >> %This is our initial distribution >> %as time goes on, it will move to the right (advection) >> %and the sides will get less steep (diffusion); >> plot(x,N(:,5)); >> plot(x,N(:,20)) >> plot(x,N(:,49)) >> >> %We can plot everything at the same time: >> h=plot(x,N); >> whos h Name Size Bytes Class h 49x1 392 double array Grand total is 49 elements using 392 bytes >> %Matlab created 49 lines and gave each one a different >> %color. colortime sets the colors so that >> %they vary linearly between rgb1 and rgb2 >> % >> %Type "edit colortime" to open it in Matlab editor >> >> g=colortime(x,t,N,[0 0 0.25], [1 0 0]);%start with dark blue and move towards red >> g=colortime(x,t,N,[0 1 0], [1 0 0]);%start with bright green and move towards red >> >> %We want to make lines thicker. First, how thick are they now? >> get(g(1),'linewidth') ans = 0.5000 >> set(g,'linewidth',3) >> diary off