Matlab初阶绘图(2022b)

绘图函数

plot( ) & others

  1. plot(x,y) plots each vector pairs (x,y)

  2. plot(y) plots each vector pairs (x,y), where x=[1 2 … n]

    Example: plot(cos(0:pi/10:2*pi));​​

  3. 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
    

  4. about plot style:​ plot(x,y,'str')​​ plots each vector pairs (x,y) using the format defined in str​​.

    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

  1. 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写法
    

  2. 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,起点与坐标原点重合)
    

  3. 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, use set ( )

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)相关推荐

  1. MATLAB初阶绘图

    目录 前言 一.初阶绘图 plot() ​ hold on/off 绘制样式​ legend()  绘制图例 title() 和 label() text() 和 annotation() Exerc ...

  2. 【台大郭彦甫】Matlab入门教程超详细学习笔记五:初阶绘图(附PPT链接)

    初阶绘图 前言 一.基础绘图 1.plot() 绘制二维线图 2.legend()添加图例 3.title()和*label()添加标题与坐标轴 4.text()和annotation()增加注解 二 ...

  3. Matlab学习(台大郭彦甫)第5节-初阶绘图

    Matlab学习(台大郭彦甫)第5节-初阶绘图 第5节 初阶绘图 5.1 基础绘图 5.1.1 plot()函数 5.1.2 hold on/off 5.1.3 Plot Style(绘图风格) 5. ...

  4. MATLAB与数学建模:初阶绘图

    以下内容为个人笔记,部分图片来源于郭老师课件或课程截图. 笔记汇总:MATLAB基础教程 课程视频:MATLAB基础教程-台大郭彦甫(14课全-高清-含课件) 文章目录 基础绘图 plot() 基本使 ...

  5. 郭彦甫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 ...

  6. MATLAB教学_05初阶绘图

    本文视频地址为: https://www.bilibili.com/video/av68228488?p=5 本文主要学习了初级绘图的一些知识. 简单的plot()函数 例如: plot(cos(0: ...

  7. MATLAB(四)初阶绘图

    文章目录 前言 plot() hold on/off Plot Style 线型.标记符号和颜色 修改线条外观 legend() title()和?label() 显示标题.标签.图例 Text()和 ...

  8. B站台湾大学郭彦甫|MATLAB 学习笔记|06 高阶绘图 Advanced Plot

    MATLAB学习笔记(06 高阶绘图 Advanced Plot) 如果想获得更好浏览体验的朋友可以转到下面链接 06 1. 对数图 (Logarithm Plots) x = logspace(-1 ...

  9. 【台大郭彦甫】Matlab入门教程超详细学习笔记六:高阶绘图(附PPT链接)

    高阶绘图 前言 一.进阶二维绘图 1. 对数图 2.一图双y轴 3. 直方图 4. 条形图 5. 饼状图 6. 极坐标图 7. 阶梯图与取样图 8. 箱线图以及误差线图 9. 填充图 二.配色 1.R ...

最新文章

  1. 2021年大数据ZooKeeper(五):ZooKeeper Java API操作
  2. DGL-LifeSci:面向化学和生物领域的 GNN 算法库
  3. python字符串27种常见的方法
  4. JavaScript创建Map对象(转)
  5. gdb调试之堆栈跟踪
  6. C++中的friend详细解析
  7. jQuery总体架构的理解
  8. c6x Linux 内核中断分析
  9. c语言的二分查找,C语言二分查找法
  10. cafffe---之params参数
  11. 【Python实例第15讲】分类概率图
  12. 【nodejs】使用put方式向后端提交数据
  13. codeforces 675D Tree Construction set
  14. linux无线网卡消失,Linux下无线网卡无法开启解决办法
  15. 值得收藏的网站----安全
  16. STM32的Flash地址是0x08000000,从0x00000000不可以?
  17. python学习之编写学员管理系统
  18. wireshark 报文分析心得 -- Identification 使用说明
  19. 特征工程中的数据标准化
  20. 1010 - 线性dp - 除虫药水

热门文章

  1. 「MySQL」从零到删库
  2. 你的眼界有多大,格局就有多大
  3. JavaScript之彻底搞懂DOM与BOM及其区别与用法
  4. MetroGAN: Simulating Urban Morphology with Generative Adversarial Network
  5. 浅谈五阶巴特沃斯滤波器硬件设计归一化法
  6. python语言与其他语言的区别_python与其他编程语言区别全在这
  7. 二叉树 - 递归计算二叉树的高度(C语言)
  8. Redis核心技术与实战-学习笔记(五)内存快照RDB
  9. 微信前端之在微信浏览器内禁用网页分享菜单的解决方案
  10. linux 网卡聚合mac,linux网卡与MAC地址绑定方法总结