python matlabplot 如何使得上下无间距_matlab基础绘图

1.基础绘图
和类似
1.1 绘图:plot()
如果绘制多条曲线,需要使用hold on-hold off,不然后面的曲线会覆盖掉前面的 。
hold on
plot(cos(0:pi/20:2*pi),'o-k');
plot(sin(0:pi/20:2*pi),'X--b');
hold off%两个一起画;不使用hold on的话,默认会覆盖掉前面那张图片
1.2 样式
plot样式
plot(x,y,‘str’)
图例:()
title()和()()()
x=0:0.5:4*pi;
y=sin(x);
h=cos(x);
w=1./(1+exp(-x));
('t=0 tp 2\pi');
(' of sin(t) and e^{-x}');
plot(x,y,'bd-',x,h,'gp:',x,w,'ro-',x,w,'c^-');%样式
title(' of sin(t) and e^{-x}');%标题
('sin(x)','cos(x)','','Gauss ');%图例
text() and ()
数学公式使用latex
x = (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 $$';%表示积分函数
text(0.25,2.5,str,'','latex'); %积分函数的位置
('arrow','X',[0.32,0.5],'Y',[0.6,0.4]); %箭头位置
小练习:
t=1:0.01:2;
f=t.*t;
g=sin(2*pi*t);
plot(t,f,'k',t,g,'ro');
('Time (ms)');
('f(t)');
title('Mini#1');
('t^2','sin(2\pi t)','','');%指定图例在左上角
2. 图像调整(
一张图片由很多对象组成;
一个对象又有很多属性 。

python matlabplot 如何使得上下无间距_matlab基础绘图

文章插图
2.1 修改图片对象的句柄()
函数
|函数|解释 |
|–|--|
|gca|返回当前图像的坐标轴axes |
|gcf|返回图像的对象|
||找到具体对象的所有孩子|
||找到图片对象的祖先|
||删除具体对象|
||找出所有的图片对象|
2.2获得或者修改图片属性
获得属性/对象:get()
修改属性:set()
两者都需要通过获取来进行实现 。
%2020.09.19
x = (0, 2*pi, 1000);
y = sin(x);
h = plot(x,y);
get(h) %获取h的信息
get(gca)%获取当前图像的axis对象的所有信息
%set(gca, 'XLim', [0, 2*pi]);%修改Xlim的取值
%set(gca, 'YLim', [-1.2, 1.2]);
xlim([0, 2*pi]);%修改Xlim的取值
【python matlabplot 如何使得上下无间距_matlab基础绘图】ylim([-1.2, 1.2]);
2.3 设置字体和坐标轴的间距(tick)
set(gca, '', 25);%设置字体大小
set(gca, 'XTick', 0:pi/2:2*pi);%Tick, YTick, ZTick - 刻度值; 由递增值组成的向量
set(gca, '', 0:90:360);
2.4 曲线的格式
线宽和曲线样式
%set(h, '', '-.',...
% '', 7.0, 'Color', 'g');%设置line的格式
plot(x,y, '-.g',... '', 7.0)
%(h);%删掉曲线h
图标(maker)的face和edge
x=rand(20,1); %rand(3,4) 返回一个 3×4 的矩阵 。
set(gca, '', 18);
plot(x,'-md','', 2, '', 'k',...
'', 'g', '', 10);
xlim([1, 20]);
2.5 小练习
t=1:0.01:2;
f=t.*t;
g=sin(2*pi*t);
plot(t,f,'k',t,g,'ro','', 2,'', 'r',...
'', 'g');
('Time (ms)');
('f(t)');
title('Mini#1');
('t^2','sin(2\pi t)','','');
set(gca,'',20,'','bold','','bold','XTick', -1:1:4);
3. 组合图片
当存在复合图像时,gcf指的是现在的图片,即.
x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
, plot(x,y1);
, plot(x,y2);
3.1 设置图像的位置和大小
3.2 一个中显示几个plots
t = 0:0.1:2*pi;
x = 3*cos(t);
y = sin(t);
(2, 2, 1);
plot(x, y);
axis%x和y轴自动调整
(2, 2, 2);
plot(x, y);
axis%x和y轴的总长度一样
(2, 2, 3);
plot(x, y);
axis equal %x和y轴的间隔一样
(2, 2, 4);
plot(x, y);
axis equal tight %Set the axisto the range of the data
axis off
axis on
4. 把保存成文件
如果想要保存成高解析度的文件,建议使用‘print’ 。
%into Files
(gcf,'','pdf');
原文链接: