b站-MATLAB教程学习4 Basic plotting(待)

这篇教程介绍了MATLAB的初级绘图技巧,包括plot函数、hold on/off的使用,图线样式设定,添加图例,设置标题和坐标标签,text与annotation的运用,以及figure的调整和保存。通过实例展示了如何绘制和定制各种图形。
摘要由CSDN通过智能技术生成

初阶绘图

(需要联系加强诶)

  1. 画图常用函数

①plot()
• plot(x,y) plots each vector pairs (x,y)
• plot(y) plots each vector pairs (x,y),where x=[1…n], n=length(y)
默认x是1,2,3…
• Example:
plot(cos(0:pi/20:2*pi));
在这里插入图片描述

②hold on/off
• Use hold on to have both plots in one figure 图像保留在一张图里
• Example:
hold on
plot(cos(0:pi/20:2pi));
plot(sin(0:pi/20:2
pi));
hold off
在这里插入图片描述③Plot Style
• plot(x,y,‘str’) plots each vector pairs (x,y) using the format defined in str
写在一起,没顺序
在这里插入图片描述
• Example:
hold on
plot(cos(0:pi/20:2pi),‘or–’);
plot(sin(0:pi/20:2
pi),‘xg:’);
hold off
在这里插入图片描述④legend 标图标
• Add legend to graph
legend(‘L1’,…)
ps:legend一定要打在plot之后才有用;legend用鼠标可以拖的
• Example:
x=0:0.5:4pi;
y=sin(x); h=cos(x); w=1./(1+exp(-x));
g=(1/(2
pi2)0.5).*exp((-1.*(x-2*pi).2)./(22^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() 标题和坐标
• title()
• xlabel()
• ylabel()
• zlabel()
• Example:
x = 0:0.1:2pi; y1 = sin(x); y2 = exp(-x);
plot(x, y1, '–
’, x, y2, ‘😮’);
xlabel(‘t = 0 to 2\pi’); %’‘是转义符 \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()
图上画数学表达式
在这里插入图片描述在这里插入图片描述ps:linspace用于产生x1,x2之间的N点行线性的矢量,其中x1、x2、N分别为起始值、终止值、元素个数。若默认N,默认点数为100。

  1. Figure Adjustment调整图
    ①画完图,可以用【查看】->【属性编辑器】里手动设置

总结起来就一句话用get找到要修改地方的handle,用set进行修改
• To fetch properties, use
get() 取回
x = linspace(0, 2*pi, 1000);
y = sin(x); h = plot(x,y);
get(h)%对line
get(gca)%对axis
• To modify properties, use
set()修改

②多图用figure()
• Example:
x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);
但是Be careful when using the gcf handle where there exists multiple figures(指代的是第二幅图)

figure位置和大小
figure(‘Position’, [left, bottom, width, height]);
在这里插入图片描述

一个figure画多个小图
• Several small plots “in a figure
subplot(m, n,1);
在这里插入图片描述• Example:
t = 0:0.1:2pi; x = 3cos(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 %相切
在这里插入图片描述③Control of Grid, Box, and Axis
在这里插入图片描述ps:grid网格 box外圈线保留x、y轴 axis外圈线都不要

④Saving Figures into Files保留图
saveas(gcf,’’,’’);
在这里插入图片描述

高解析度,参考print

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值