MATLAB基本绘图

一.基本命令:

plot(); 绘图命令

hold on,hold off 清除之前的图形

legend();多图标注

xlabel();

ylabel();

zlable();

title();

text();文本

annotation();用于在图上绘制符号

关于图像字体和轴的设置命令

二.命令介绍

2.1

plot(); 绘图命令

%hold on,hold off 清除之前的图形
%plot(x,y)
%plot(y),x=1,2,3,4...
hold on 
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off

输出结果为

 2.2 legend();多图标注

xlabel();

ylabel();

title();

%legend() 图标
%xlabel
%ylabel
%title
%zlable
%hold on 
x=0:0.5:4*pi;
y=sin(x);
h=cos(x);
w=1./(1+exp(-x));
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-');
legend('sin(x)','cos(x)','sigmoid');
xlabel('x');
ylabel('y');
title('function');
%hold off

 2.3text();文本

annotation();用于在图上绘制符号

%text();
%annotation();
x=linspace(0,3);
y=x.^2.*sin(x);
plot(x,y);
line([2,2],[0,2^2*sin(2)]);
str='$$ \int_{0}^{2} x^2\sin(x) dx $$';
%'Interpreter','latex'只用latex的符号
text(0.25,2.5,str,'Interpreter','latex');
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);

三. 图像字体和轴的设置命令

%%
%gca、gcf是专门针对Figure和Axes的指令,如果针对Line,则需要定义h=plot(x,y)
%get()用来获取特征;
%set()用来设置特征;
x=linspace(0,2*pi,1000);
y=sin(x);
plot(x,y);
h=plot(x,y);
get(h)

%set axes limits设置坐标的最大最小值
x=linspace(0,2*pi,1000);
y=sin(x);
plot(x,y);
set(gca,'XLim',[0,2*pi]);%xlim([0,2*pi]);
set(gca,'YLim',[-1.5,1.5]);%ylim([-1.5,1.5]);

%setting font and tick of axes设置轴的字体和刻度
x=linspace(0,2*pi,1000);
y=sin(x);
plot(x,y)
set(gca,'FontSize',15);%轴的字体设置
%set(gca,'XTick',0:pi/2:2*pi);%设置轴的刻度
set(gca,'XTickLabel',0:90:360);
%set(gca,'FontName','symbol');
set(gca,'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2p'});
%%
x=0:pi/100:2*pi;
plot(x,sin(x));
set(gca,'xtick',[ 0 0.5*pi pi 1.5*pi 2*pi]);
xticklabels({'0','0.5\pi','\pi','1.5\pi','2\pi'})

%%
%Multiple Figure
x=-10:0.1:10;
y1=x.^2-8;
y2=exp(x);
figure,plot(x,y1);
figure,plot(x,y2);
%figure position and size
%figure('Position',[left,bottom,width,height]);
figure('Position',[2,2,2,2]);
%%
%several plots in one figure ,subplot(m.n,t)
x=-10:0.1:10;
y1=x.^2-8;
y2=exp(x);
subplot(2,1,1);
plot(x,y1);
subplot(2,1,2);
plot(x,y2);

 四.参考ppt

 

 

  • 23
    点赞
  • 179
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值