matlab初阶绘图

matlab初阶绘图

 plot(cos(0:pi/20:2*pi))

在这里插入图片描述

matlab将会清除之前的图像保留最新的图

plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));

what can we do to solve this problem?

hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off

啦啦啦啦

曲线性质

plot(x,y,“str”)
hold on
plot(cos(0:pi/20:2*pi),"d-b");
plot(sin(0:pi/20:2*pi),"d--g");
% plot(x,y,'-.g',...'LineWidth', 7.0); 线宽多长
% 就是针对Data markers用颜色填充里面空心的部分
plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor','k',...'MarkerFaceColor','g','MarkerSize', 10);
hold off
Matlab画图plot(X1,Y1,‘b -’,x1,y1,‘ro’,‘MarkerFaceColor’,‘r’)

在这里插入图片描述

下面2张图对比Data markers部分

在这里插入图片描述在这里插入图片描述

more properties

在这里插入图片描述

the title of lines

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 and label

x = 0:0.1:2*pi; y1 = sin(x); y2 = exp(-x);
plot(x, y1, '--*', x, y2, ':o');
xlabel('t = 0 to 2\pi');   % 斜杠 转义字符
ylabel('values of sin(t) and e^{-x}')  %大括号会把-x当成一个整体 小括号只会把(当成一个整体
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');
在这里插入图片描述

text and annotation

x = linspace(0,3); y = x.^2.*sin(x); plot(x,y); %0到3的等差数列 n=100
line([2,2],[0,2^2*sin(2)]); %对应的就是画x=2那条直线
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$'; %积分符号latex代码
text(0.25,2.5,str,'Interpreter','latex');  % 积分的坐标位置
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]); 
数学公式代码
在这里插入图片描述

exercise

x=0:0.01:2;
y1=power(x,2);
y2=sin(2*pi*x);
plot(x,y1,'-k',x,y2,'or');
xlabel('Time(ms)');
ylabel('f(t)');
title('Mini Assignment #1')
hleg1=legend('x^2','sin(2/pix)');
set(hleg1,'Location','NorthWest')

Getting Object Properties

获得h的属性
x = linspace(0, 2*pi, 1000);
y = sin(x); h = plot(x,y);
get(h) 

在这里插入图片描述在这里插入图片描述

gcf指figure图形,gca指坐标轴
set(gca,'XLim', [0, 2*pi]);   %修改X轴的上下限
set(gca,'YLim', [-1.2, 1.2]); %修改Y轴的上下限
% xlim([0, 2*pi]);  等同上面的
% ylim([-1.2, 1.2]);
set(gca,'XTick', 0:pi/2:2*pi);  %修改X轴的上下限
set(gca,'XTickLabel', 0:90:360);  %X轴上对应的数值用 0:90:360表式
set(gca,'FontName', 'latex');
set(gca,'XTickLabel', {'0', '\pi/2', '\pi', '3\pi/2', '2\pi'});
在这里插入图片描述

Multiple Figures

x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);
% figure('Position', [left, bottom, width, height]);
% 设定figurs的位置 
% left, bottom调整位置
% width, height调整图的大小

Matlab之画图的位置管理
在这里插入图片描述

Several Plots in One Figure

subplot(m, n,1)
%与python中一致m*n个图,1就是代表第一张图,一般用循环for来操纵第i张图
在这里插入图片描述
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
% axis square/将当前坐标系图形设置为方形。横轴及纵轴比例是1:1
subplot(2, 2, 3); plot(x, y); axis equal   
% axis equal刻度是等长的
subplot(2, 2, 4); plot(x, y); axis equal tight
% 数据范围就是坐标范围
在这里插入图片描述
matlab中axis square和axis equal的区别
Matlab中axis函数用法总结
在这里插入图片描述
% 附上代码有意者删除%可以测试观察
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
subplot(2, 2, 3); plot(x, y); axis equal
subplot(2, 2, 4); plot(x, y); axis equal tight
% grid on  %加网格线
% box off  %取消上层和右边的轴
% axis on %取消XY轴

Saving Figures into Files 保存图片

saveas(gcf,'<filename>','<formattype>');
Vector意思就是无限放大照片照样清晰
Image照片由若干个像素点构成,放大之后像素点稀疏,照片比较模糊
在这里插入图片描述 [郭彦甫老师课程中的PPT,提取码7777](https://pan.baidu.com/s/1l2bcuIYlpAEgeD1-eYn0fA) 感谢你的阅读
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值