Plot form 'Data'
plot(x,y);
plot(y); %x = [1…n], n = length(y)
EG1:
plot(cos(0:pi/20:2*pi));
EG1.1:
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi)); %会覆盖旧的图形,除非使用hold指令
hold on/off
EG:
hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi)); %两个图像在一个坐标轴
hold off
plot(x,y,'str')
%str是图像的一些参数进行一个改变的动作,具体指令如下所示
-
Data markers
-
Dot(.)——.
-
Asterisk( * )——*
-
Cross(×)——X
-
Circle(○)——o
-
Plus sign(+)——+
-
Square(□)——s
-
Diamond(♢)——d
-
Five-pointed star(☆)——p
-
Triangle(下三角)——v
-
Triangle(上三角)——^
-
Triangle(左三角【指向右边】)——<
-
Triangle(右三角【指向左边】)——>
-
hexagram——H
-
-
Line types
-
Solid line -
-
Dashed line --
-
Dash-dotted line -.
-
Dotted line :
-
-
Colors
-
Black——k
-
Blue——b
-
Cyan——c
-
Green——g
-
Magenta——m
-
Red——r
-
White——w
-
Yellow——y
-
更多详情查看linespec
legend()
%标记图例
EG1:
x = 0:0.5:4*pi;
y = sin(x);
h = cos(x);
w = 1./(1+exp(-x));
g = (1/(2*pi*2)^0.5).*exp((-1.*(x-2*pi).^2)./(2*2^2));
plot(x,y,'bd-',x,h,'gp',x,w,'ro-',x,g,'c^-');
legend('sin(x)','cos(x)','Sigmoid','Gauss function');
title()
xlabel()
ylabel()
zlabel() %三维画图
%加标题
EG:
x = 0:0.1:2*pi;
y1 = sin(x);
y2 = exp(-x);
plot(x,y1,'--*',x,y2,':o');
xlabel('t = 0 to 2\pi'); %输出2π,如果input‘2π’,output‘6.28’
ylabel('values of sin(t) and e^{-x}'); %特殊字符e^{-x}
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');
text() and annotation()
%使用LaTex达到一些花里胡哨的效果
EG1:
x = linspace(0,3); %定义域
y = x.^2.*sin(x);
plot(x,y);
line([2,2],[0,2^2*sin(2)]); %在图上画一个line
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$'; %表示定积分符号
text(0.25,2.5,str,'Interpreter','latex'); %后面的两个引号是固定表示,详情自查
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]); %生成箭头
Figure Adjustment
Graphical Objects: Figure,Axes,Line
Handle of An Object
gca %axes
gcf %figure
allchild %find all children of specified objects
ancestor %find ancestor of graphics object
delete %delete an object
findall %dinf all graphics objects
Fetch or Modifying Properties
-
To fetch properties
get();
eg1:
x = linspace(1,2*pi,1000);
y = sin(x);
plot(x,y);
h = plot(x,y);
get(h);
get(gca)
eg2:
set(gca,'XLim',[0,2*pi]);
set(gca,'YLim',[-1.2,1.2]);
set(gca,'FontSize',25); %坐标数字大小
%%
set(gca,'XTick',0:pi/2:2*pi); %坐标点位
set(gca,'XTickLabel',0:90:360); %坐标表示
%%
set(gca,'FontName','symbol'); %转handle
set(gca,'XTickLabel',{'0','p/2','p','3p/2','2p'}); %改表示
Line Specification
set(h,'LineStyle','-.','LineWidth',7.0,'Color','g');
%%
plot(x,y,'-.g',...,'LineWidth',7.0);
%delete(),删除图像,但是不删除变量
Maker Specification
x = rand(20,1);
set(gca,'FontSize',18);
plot(x,'-md','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColoe'...
'g','MarkerSize',10);
xlim([1,20]);
Multiple Figures
x = -10:0.1:10; y1 = x.^2-8; y2 = exp(x); figure plot(x,y1); figure plot(x,y2); %gca与gcf只能找到最新的图像
figure('Position',[left,bottom],width,height); %%%%%%% subplot(m,n,1); %多图放一张 n:column;m:row;1:1~n个图 eg: t = 0:0.1:2*pi; x = 3*cos(t); y = sin(t); subplot(2,2,1); plot(x,y); axis normal; subplot(2,2,2); plot(x,y); axis square; %x与y轴的整体长度相等 subplot(2,2,3); plot(x,y); axis equal; %x与y轴上面的单位长度等距 subplot(2,2,4); plot(x,y); axis equal tight; %贴近图像
grid on/off %格线 box on/off %边框 axis on/off %坐标图 axis nomal axis aquare axis equal axis equal tight axis image axis ij axis xy %自查
Saving Figures into Files
saveas(gcf,'<filename>','<formattype>'); %%%%%% ---Bitmap jpeg png tiff bmpmono bmp bmp256 ---Vector(sanse推荐) pdf eps epsc meta svg ps psc %更多查询print