Matlab学习笔记[4](Two-Dimensional Plots)

4.1 THE plot COMMAND

 

plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)

 

 x,y分别是大小相等的Vector

 

Line Specifiers

 

solid (default)    -
dotted               :
dashed              --
dash-dot            -.

 

 The line color specifiers

 

red r
green g
blue b

 

 The marker type specifiers

 

plus sign +
circle o
asterisk *

 

 例子

plot(x,y,‘g:d’)

plot(x,y,‘--y’)

 

Property Name and Property Value:

 

LineWidth
MarkerSize
MarkerEdgeColor
MarkerFaceColor

 

 例子

 

plot(x,y,‘-mo’,‘LineWidth’,2,‘markersize’,12,‘MarkerEdgeColor’,‘g’,‘markerfacecolor’,‘y’)

 

 

4.2 THE fplot COMMAND

 

fplot(‘function’,limits,‘line specifiers’)

 

 fplot('x^2+4*sin(2*x)-1',[-3 3])

 line specifiers和plot一样的

 

4.3 PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT

1.Using the plot Command

plot(x,y,u,v,t,h)
plot(x,y,‘-b’,u,v,‘--r’,t,h,‘g:’)

 

2.Using the hold on and hold off Commands

x=[-2:0.01:4];
y=3*x.^3-26*x+6;
yd=9*x.^2-26;
ydd=18*x;
plot(x,y,'-b')
hold on
plot(x,yd,'--r')
plot(x,ydd,':k')
hold off
 

3.Using the line Command

line(x,y,‘PropertyName’,PropertyValue)
  line(x,y,‘linestyle’,‘--’,‘color’,‘r’,‘marker’,‘o’)
x=[-2:0.01:4];
y=3*x.^3-26*x+6;
yd=9*x.^2-26;
ydd=18*x;
plot(x,y,'LineStyle','-','color','b')
//画好图之后加上去的
line(x,yd,'LineStyle','--','color','r')
line(x,ydd,'linestyle',':','color','k')

 4.FORMATTING A PLOT

The xlabel and ylabel commands

xlabel(‘text as string’)
ylabel(‘text as string’)

 The title command

title(‘text as string’)

 The text command:

text(x,y,‘text as string’)
gtext(‘text as string’)

 The legend command

legend(‘string1’,‘string2’, ..... ,pos)

 Formatting the text within the xlabel, ylabel, title, text and legend commands

\bf bold font 
\fontname{fontname} specified font is used
\it italic style 
\fontsize{fontsize} specified font size is used
\rm normal font
text(x,y,‘text as string’,PropertyName,PropertyValue)

  The axis command:

axis([xmin,xmax,ymin,ymax]) 
//Sets the limits of both the x and y axes (xmin, xmax, ymin, and ymax are numbers).

 例子

 

x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
title('\fontname{Arial}Light Intensity as a Function of Distance','FontSize',14)
axis([8 24 0 1200])
text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2)
hold on
plot(xd,yd,'ro--','linewidth',1.0,'markersize',10)
legend('Theory','Experiment',0)
hold off
 

你可能感兴趣的:(matlab)