画图:①生成数字点 ②连线
只生成最后一个
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
两条线都生成
hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off
• plot(x,y,'str')
str中的符号
legend('L1',)
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');
标记图片名称和x,y,z轴
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}')
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');
使用到LaTex 箭头
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 $$'; % '$$...$$' 意味着 latex, '\int'意味着积分符号,'{0}^{2}'意味着在(0,2)区间内积分
text(0.25,2.5,str,'Interpreter','latex');
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]); %X,Y的区间
图形对象
步骤:
① 识别一个对象的句柄
② 获取或修改handle
① Identifying the Handle of An Object
h = plot(x,y);
②Fetching or Modifying Properties
get( ) %获取属性
set( ) %修改属性
x = linspace(0, 2*pi, 1000);
y = sin(x); h = plot(x,y);
get(h)
得到一个sin(x)图像
set(gca, 'XLim', [0, 2*pi]);
set(gca, 'YLim', [-1.2, 1.2]);
set(gca, 'FontSize', 25); %25是字号
set(gca, 'XTick', 0:pi/2:2*pi); %坐标轴刻度间距
set(gca, 'XTickLabel', 0:90:360); %坐标轴刻度标记
set(gca, 'FontName', 'symbol');
set(gca, 'XTickLabel', {'0', 'p/2', 'p', '3p/2', '2p'}); %'p' means 'pi'
h = plot(x,y);
set(h, 'LineStyle','-.', ...
'LineWidth', 7.0, ...
'Color', 'g');
或者
plot(x,y, '-.g',...
'LineWidth', 7.0);
x=rand(20,1); set(gca, 'FontSize', 18);
plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor', 'k',...
'MarkerFaceColor', 'g', 'MarkerSize', 10);
xlim([1, 20]);
% face color
% edge color 边界颜色
x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);
subplot(m, n,1);
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
1 使用saveas(fig,filename)命令可以将图形对象保存到文件中,其中fig为图形句柄,filname为文件名
saveas(gcf, 'myfigure.png')
saveas(gcf,'<filename>','<formattype>');
%(版权声明:本文为CSDN博主「ncepu_Chen」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ncepu_Chen/article/details/103097452)
使用saveas()函数将图像保存成位图时,会发生失真.要精确控制生成图片的质量,可以使用print()函数
2 需要高度解析
print