Matlab初阶绘图(2022b)
Matlab初阶绘图(2022b)
绘图函数
plot( ) & others
plot(x,y) plots each vector pairs (x,y)
plot(y) plots each vector pairs (x,y), where x=[1 2 … n]
Example:
plot(cos(0:pi/10:2*pi));
if you want to draw 2 or plots, use
hold on/off
to have both plots in one figure.hold on plot(cos(0:pi/20:2*pi)); plot(sin(0:pi/20:2*pi)); hold off
about plot style:
plot(x,y,'str')
plots each vector pairs (x,y) using the format defined instr
.hold on plot(cos(0:pi/20:2*pi),'or--'); plot(sin(0:pi/20:2*pi),'^b:'); hold off% codes below are wrong! --> plot(cos(0:pi/20:2*pi),'or--',sin(0:pi/20:2*pi),'^b:') %错误使用 plot %数据必须为单个 y 值输入或者一对或多对 x 和 y 值。
POLISHMENT
Add legend to graph
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^-');
Lack ‘name’, title, xlable, ylable …
Make a little adjustment !
legend('sin(x)','cos(x)','Sigmoid','Gauss function'); xlabel('x=0 to x=4\pi'); ylabel('values of different functions'); title('Function Plots'); % 引号内可以使用Markdown写法
text( ) & annotation( )
x = linspace(0,3); % x的取值范围 y = x.^2.*sin(x); plot(x,y); line([2,2],[0,2^2*sin(2)]); % 括号内前者为line的x坐标范围,后者同理,为y取值范围 str = '$$\int_{0}^{2} x^2\sin(x) \textup dx$$'; text(0.25,2.5,str,'Interpreter','latex'); % Latex写法好麻烦啊,$$转义,'\test'貌似不能用 % 前两个数为公式起始点坐标(自变量的值) annotation('arrow','X',[0.32,0.45],'Y',[0.6,0.4]); % XY后的范围貌似指的是在图窗中的比例(即横纵都为1,起点与坐标原点重合)
Excercise
t=linspace(1,2); % t=1:0.1:2; % 找不同 f=t.^2; % 从矩阵运算角度理解为啥要用点乘幂。。。 g=sin(2*pi*t); plot(t,f,'k-',t,g,'ro'); legend('t^2','sin2\pit'); xlabel('Time(ms)'); ylabel('f(t)'); title('Mini Assignment #1');
Figure Adjustment
Several properties:
Font & Size, Line width, Axis limit, Tick position, Tick label
Identify the Handle of An Object
When create
h = plot(x,y);
‘h’ is the handle of this ‘line’ of function.
To fetch properties, use
get ( )
; To modify properties, useset ( )
Setting examples:
Axis:
x = linspace(0, 2*pi, 1000);
% 1000为点的数量,不输默认100
y = sin(x); h = plot(x,y);
get(h)
...
% codes above
set(gca, 'XLim', [0, 2*pi]);
set(gca, 'YLim', [-1.2, 1.2]);
% modify the length of axis
set(gca, 'FontSize', 25);
set(gca, 'XTick', 0:pi/2:2*pi);
set(gca, 'XTickLabel', 0:90:360);
% xtick 的替换
set(gca, 'FontName', 'sym');
set(gca, 'XTickLabel', {'0', '\pi/2', '\pi', '3\pi/2', '2\pi'});
% symbol(sym)
Line:
...
set(h, 'LineStyle', '-.','LineWidth', 7.0, 'Color', 'g');
% another choice ->
% plot(x,y, '-.g','LineWidth', 7.0);
Marker:
x=rand(20,1); set(gca, 'FontSize', 18);
plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor', 'k','MarkerFaceColor', 'g', 'MarkerSize', 10);
xlim([1, 20]);
% equal to 'set(gca, 'XLim', [1,20]);'
Other applications
存在多图时进行图操作,操作的是当前图 (current plot), 例如最后一张图上的操作。
draw many lines in different axis:
x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);
position:
draw many plots in one window:
subplot( )
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
Matlab初阶绘图(2022b)相关推荐
- MATLAB初阶绘图
目录 前言 一.初阶绘图 plot() hold on/off 绘制样式 legend() 绘制图例 title() 和 label() text() 和 annotation() Exerc ...
- 【台大郭彦甫】Matlab入门教程超详细学习笔记五:初阶绘图(附PPT链接)
初阶绘图 前言 一.基础绘图 1.plot() 绘制二维线图 2.legend()添加图例 3.title()和*label()添加标题与坐标轴 4.text()和annotation()增加注解 二 ...
- Matlab学习(台大郭彦甫)第5节-初阶绘图
Matlab学习(台大郭彦甫)第5节-初阶绘图 第5节 初阶绘图 5.1 基础绘图 5.1.1 plot()函数 5.1.2 hold on/off 5.1.3 Plot Style(绘图风格) 5. ...
- MATLAB与数学建模:初阶绘图
以下内容为个人笔记,部分图片来源于郭老师课件或课程截图. 笔记汇总:MATLAB基础教程 课程视频:MATLAB基础教程-台大郭彦甫(14课全-高清-含课件) 文章目录 基础绘图 plot() 基本使 ...
- 郭彦甫Matlab第四节笔记——初阶绘图
目录 1.basic plot 1.1 plot from data 1.1.1 plot() 1.1.2 hold on 1.1.3 plot style 1.1.4 legend 1.1.5 ...
- MATLAB教学_05初阶绘图
本文视频地址为: https://www.bilibili.com/video/av68228488?p=5 本文主要学习了初级绘图的一些知识. 简单的plot()函数 例如: plot(cos(0: ...
- MATLAB(四)初阶绘图
文章目录 前言 plot() hold on/off Plot Style 线型.标记符号和颜色 修改线条外观 legend() title()和?label() 显示标题.标签.图例 Text()和 ...
- B站台湾大学郭彦甫|MATLAB 学习笔记|06 高阶绘图 Advanced Plot
MATLAB学习笔记(06 高阶绘图 Advanced Plot) 如果想获得更好浏览体验的朋友可以转到下面链接 06 1. 对数图 (Logarithm Plots) x = logspace(-1 ...
- 【台大郭彦甫】Matlab入门教程超详细学习笔记六:高阶绘图(附PPT链接)
高阶绘图 前言 一.进阶二维绘图 1. 对数图 2.一图双y轴 3. 直方图 4. 条形图 5. 饼状图 6. 极坐标图 7. 阶梯图与取样图 8. 箱线图以及误差线图 9. 填充图 二.配色 1.R ...
最新文章
- 2021年大数据ZooKeeper(五):ZooKeeper Java API操作
- DGL-LifeSci:面向化学和生物领域的 GNN 算法库
- python字符串27种常见的方法
- JavaScript创建Map对象(转)
- gdb调试之堆栈跟踪
- C++中的friend详细解析
- jQuery总体架构的理解
- c6x Linux 内核中断分析
- c语言的二分查找,C语言二分查找法
- cafffe---之params参数
- 【Python实例第15讲】分类概率图
- 【nodejs】使用put方式向后端提交数据
- codeforces 675D Tree Construction set
- linux无线网卡消失,Linux下无线网卡无法开启解决办法
- 值得收藏的网站----安全
- STM32的Flash地址是0x08000000,从0x00000000不可以?
- python学习之编写学员管理系统
- wireshark 报文分析心得 -- Identification 使用说明
- 特征工程中的数据标准化
- 1010 - 线性dp - 除虫药水
热门文章
- 「MySQL」从零到删库
- 你的眼界有多大,格局就有多大
- JavaScript之彻底搞懂DOM与BOM及其区别与用法
- MetroGAN: Simulating Urban Morphology with Generative Adversarial Network
- 浅谈五阶巴特沃斯滤波器硬件设计归一化法
- python语言与其他语言的区别_python与其他编程语言区别全在这
- 二叉树 - 递归计算二叉树的高度(C语言)
- Redis核心技术与实战-学习笔记(五)内存快照RDB
- 微信前端之在微信浏览器内禁用网页分享菜单的解决方案
- linux 网卡聚合mac,linux网卡与MAC地址绑定方法总结