User Tools

Site Tools


gibson:teaching:spring-2016:math445:lecture:scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:spring-2016:math445:lecture:scripts [2016/02/01 09:07]
gibson
gibson:teaching:spring-2016:math445:lecture:scripts [2016/02/03 13:54] (current)
gibson [Logarithmic plots]
Line 4: Line 4:
 <​code>​ <​code>​
   Matlab scripting   Matlab scripting
-  plot, semilogy, semilogx, loglog +  ​linestyles and plot modifiers: ​ 
-  xlabel, ylabel, title, legend, axis, grid, clf,  +    xlabel, ylabel, title, legend, axis, grid, clf, 
-  linestyles+
   load, save   load, save
-  what, pwd+  ​plot, semilogy, semilogx, loglog 
 +  ​what, who, pwd, ls 
 </​code>​ </​code>​
  
Line 45: Line 45:
  
 <code matlab> <code matlab>
-plotsincos ​   ​ 
- 
 >> plotsincos % execute the plotsincos script >> plotsincos % execute the plotsincos script
 </​code>​ </​code>​
Line 53: Line 51:
 {{ :​gibson:​teaching:​spring-2016:​math445:​sincos.png?​direct&​400 |}} {{ :​gibson:​teaching:​spring-2016:​math445:​sincos.png?​direct&​400 |}}
  
-===== Markers ​and line styles ​=====+===== Line styles ​and markers ===== 
 + 
 +The above plotting script used the matlab **linestyle** codes ''​ '​b-'​ ''​ and ''​ '​r-'​ ''​ to generate blue and red curves for $\cos x$ and $\sin x$. Matlab'​s **help** function provides a pretty good description of how line and marker style codes work. 
 + 
 +<code matlab>​ 
 + 
 +>> help plot 
 +    
 +   % clip out irrelevant stuff here  
 +    
 +   ​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 ​            ​(none) ​ no line 
 +           ​y ​    ​yellow ​       s     ​square 
 +           ​k ​    ​black ​        ​d ​    ​diamond 
 +           ​w ​    ​white ​        ​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. 
 + </​code>​ 
 + 
 +===== Plot modifiers ===== 
 + 
 +Some helpful commands for modifying plots 
 + 
 +<code matlab>​ 
 +xlabel('​foo'​) % add an x label 
 +ylabel('​bar'​) % add a y label 
 +title('​baz'​) ​ % add a title 
 +legend('​first',​ '​second',​ '​third'​) % add a legend with these labels 
 +axis on       % turn on axes and ticks (default) 
 +axis off      % turn off axes and ticks 
 +axis square ​  % make the plot square 
 +axis equal    % scale the x and y axes the same 
 +axis([xmin xmax ymin ymax]) % force these specific bounds on the axes 
 +grid on       % turn on grid markers 
 +grid off      % turn off grid markers 
 +hold on       % hold the current plot; the next plot will be plotted on top of this one 
 +hold off      % release the current plot; the next plot will erase this one 
 +clf           % clear figure (erase current plot) 
 +figure(2) ​    % open new figure window, numbered 2 
 +</​code>​
  
-The above plotting script used the matl''​ '​r-'​ ''​ and ''​ '​b-'​ ''​ to generate ​ 
  
gibson/teaching/spring-2016/math445/lecture/scripts.1454346434.txt.gz · Last modified: 2016/02/01 09:07 by gibson