目录

前言

一、初阶绘图

plot() ​

hold on/off

绘制样式​

legend()  绘制图例

title() 和 label()

text() 和 annotation()

Exercise​

二、图形调整

图形属性

修改图形属性

获取对象的句柄

获取或修改对象属性

获取线的属性

获取坐标轴(axes)的属性

坐标轴属性

设定坐标轴上下限

设定坐标轴字号和刻度

修改坐标轴字体和刻度标签

图线属性

标记点的属性

Exercise

多个图形

指定图形位置和大小​

在一个图形中绘制多个图形

网格、框和轴的控制

将图形保存到文件中

前言

为在B站跟随台湾大学郭彦甫老师学习matlab的笔记,截图来自郭老师PPT,部分内容参考B站弹幕和评论,仅供学习参考。


一、初阶绘图

plot() 

>> plot(cos(0:pi/20:2*pi))

matlab 绘制会将上一次的绘制覆盖

hold on/off

开始在上一次的图上继续绘制,停止在上一次的图上继续绘制,可实现同一图之中不同函数图像

>> hold on
plot(cos(0:pi/20:2*pi));
plot(sin(0:pi/20:2*pi));
hold off

绘制样式

hold on
plot(cos(0:pi/20:2*pi),'or--');
plot(sin(0:pi/20:2*pi),'xg:');
hold off

legend()  绘制图例

使用 legeng('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');

title() 和 label()

使用title() 添加图名

使用 xlabel() 添加横坐标,ylabel() 添加纵坐标,zlabel() 添加竖座标

x = 0:0.1:2*pi; y1 = sin(x); y2 = exp(-x);
plot(x, y1, '--*', x, y2, ':o');
xlabel('t = 0 to 2\pi');        %字符pi需要使用反义符号\
ylabel('values of sin(t) and e^{-x}')       %字符幂只用特殊符号
title('Function Plots of sin(t) and e^{-x}');
legend('sin(t)','e^{-x}');

text() 和 annotation()

添加文字和注解

使用 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中字符串形式
text(0.25,2.5,str,'Interpreter','latex');       %绘制积分式
annotation('arrow','X',[0.32,0.5],'Y',[0.6,0.4]);

Exercise

x=linspace(1,2);
f=x.^2;
g=sin(2*pi.*x);
plot(x,f,'b-',x,g,'or');
title('Mini Assignment#1');
legend('t^{2}','sin(2\pit)');
xlabel('Time(ms)');
ylabel('f(t)');

二、图形调整

调整图形的字体、字号、线宽、坐标轴轴上下限、标记位置、标记标签

图形属性

修改图形属性

表示一个对象的句柄

修改一个对象的属性

获取对象的句柄

在绘图时获取

h=plot(x,y);

实用函数

获取或修改对象属性

获取用 get()

修改用 set()

获取线的属性

>> x = linspace(0, 2*pi, 1000);
y = sin(x); h = plot(x,y);
get(h)AlignVertexCenters: 'off'Annotation: [1×1 matlab.graphics.eventdata.Annotation]BeingDeleted: 'off'BusyAction: 'queue'ButtonDownFcn: ''Children: [0×0 GraphicsPlaceholder]Clipping: 'on'Color: [0 0.4470 0.7410]CreateFcn: ''DeleteFcn: ''DisplayName: ''HandleVisibility: 'on'HitTest: 'on'Interruptible: 'on'LineJoin: 'round'LineStyle: '-'LineWidth: 0.5000Marker: 'none'MarkerEdgeColor: 'auto'MarkerFaceColor: 'none'MarkerIndices: [1×1000 uint64]MarkerSize: 6Parent: [1×1 Axes]PickableParts: 'visible'Selected: 'off'SelectionHighlight: 'on'Tag: ''Type: 'line'UIContextMenu: [0×0 GraphicsPlaceholder]UserData: []Visible: 'on'XData: [1×1000 double]XDataMode: 'manual'XDataSource: ''YData: [1×1000 double]YDataSource: ''ZData: [1×0 double]ZDataSource: ''

获取坐标轴(axes)的属性

>> get(gca)ALim: [0 1]ALimMode: 'auto'ActivePositionProperty: 'outerposition'AmbientLightColor: [1 1 1]BeingDeleted: 'off'Box: 'on'BoxStyle: 'back'BusyAction: 'queue'ButtonDownFcn: ''CLim: [0 1]CLimMode: 'auto'CameraPosition: [3.5000 0 17.3205]CameraPositionMode: 'auto'CameraTarget: [3.5000 0 0]CameraTargetMode: 'auto'CameraUpVector: [0 1 0]CameraUpVectorMode: 'auto'CameraViewAngle: 6.6086CameraViewAngleMode: 'auto'Children: [1×1 Line]Clipping: 'on'ClippingStyle: '3dbox'Color: [1 1 1]ColorOrder: [7×3 double]ColorOrderIndex: 2CreateFcn: ''CurrentPoint: [2×3 double]DataAspectRatio: [3.5000 1 1]DataAspectRatioMode: 'auto'DeleteFcn: ''FontAngle: 'normal'FontName: 'Helvetica'FontSize: 10FontSmoothing: 'on'FontUnits: 'points'FontWeight: 'normal'GridAlpha: 0.1500GridAlphaMode: 'auto'GridColor: [0.1500 0.1500 0.1500]GridColorMode: 'auto'GridLineStyle: '-'HandleVisibility: 'on'HitTest: 'on'Interruptible: 'on'LabelFontSizeMultiplier: 1.1000Layer: 'bottom'Legend: [0×0 GraphicsPlaceholder]LineStyleOrder: '-'LineStyleOrderIndex: 1LineWidth: 0.5000MinorGridAlpha: 0.2500MinorGridAlphaMode: 'auto'MinorGridColor: [0.1000 0.1000 0.1000]MinorGridColorMode: 'auto'MinorGridLineStyle: ':'NextPlot: 'replace'OuterPosition: [0 0 1 1]Parent: [1×1 Figure]PickableParts: 'visible'PlotBoxAspectRatio: [1 0.7896 0.7896]PlotBoxAspectRatioMode: 'auto'Position: [0.1300 0.1100 0.7750 0.8150]Projection: 'orthographic'Selected: 'off'SelectionHighlight: 'on'SortMethod: 'childorder'Tag: ''TickDir: 'in'TickDirMode: 'auto'TickLabelInterpreter: 'tex'TickLength: [0.0100 0.0250]TightInset: [0.0512 0.0540 0.0071 0.0206]Title: [1×1 Text]TitleFontSizeMultiplier: 1.1000TitleFontWeight: 'normal'Type: 'axes'UIContextMenu: [0×0 GraphicsPlaceholder]Units: 'normalized'UserData: []View: [0 90]Visible: 'on'XAxis: [1×1 NumericRuler]XAxisLocation: 'bottom'XColor: [0.1500 0.1500 0.1500]XColorMode: 'auto'XDir: 'normal'XGrid: 'off'XLabel: [1×1 Text]XLim: [0 7]XLimMode: 'auto'XMinorGrid: 'off'XMinorTick: 'off'XScale: 'linear'XTick: [0 1 2 3 4 5 6 7]XTickLabel: {8×1 cell}XTickLabelMode: 'auto'XTickLabelRotation: 0XTickMode: 'auto'YAxis: [1×1 NumericRuler]YAxisLocation: 'left'YColor: [0.1500 0.1500 0.1500]YColorMode: 'auto'YDir: 'normal'YGrid: 'off'YLabel: [1×1 Text]YLim: [-1 1]YLimMode: 'auto'YMinorGrid: 'off'YMinorTick: 'off'YScale: 'linear'YTick: [-1 -0.8000 -0.6000 -0.4000 -0.2000 0 0.2000 0.4000 0.6000 0.8000 1]YTickLabel: {11×1 cell}YTickLabelMode: 'auto'YTickLabelRotation: 0YTickMode: 'auto'ZAxis: [1×1 NumericRuler]ZColor: [0.1500 0.1500 0.1500]ZColorMode: 'auto'ZDir: 'normal'ZGrid: 'off'ZLabel: [1×1 Text]ZLim: [-1 1]ZLimMode: 'auto'ZMinorGrid: 'off'ZMinorTick: 'off'ZScale: 'linear'ZTick: [-1 0 1]ZTickLabel: ''ZTickLabelMode: 'auto'ZTickLabelRotation: 0ZTickMode: 'auto'

坐标轴属性

设定坐标轴上下限

gca 表示坐标轴

>> set(gca, 'XLim', [0, 2*pi]);
set(gca, 'YLim', [-1.2, 1.2]);

使用如下代码也可完成同样操作

>> xlim([0, 2*pi]);
ylim([-1.2, 1.2]);

设定坐标轴字号和刻度

修改坐标轴刻度和刻度标签

>> set(gca, 'XTick', 0:pi/2:2*pi);
set(gca, 'XTickLabel', 0:90:360);

修改坐标轴字体和刻度标签

>> set(gca, 'FontName', 'tex');
set(gca, 'XTickLabel', {'0', '\pi/2', '\pi', '3\pi/2', '2\pi'});
%\pi为pi在tex字体中的转义

图线属性

修改图线的属性

>> set(h, 'LineStyle', '-.','LineWidth', 7.0, 'Color', 'g');

在绘制时可以指定属性

>> plot(x,y, '-.g','LineWidth', 7.0);

标记点的属性

MarkerEdgeColor 标记点边框颜色

MarkerFaceColor 标记点填充色

MarkerSize 标记点大小

'-md' 表示绘制菱形(diamond)标记点的直线(-)品红色(magenta)

>> x=rand(20,1); set(gca, 'FontSize', 18);
plot(x,'-md','LineWidth', 2, 'MarkerEdgeColor', 'k','MarkerFaceColor', 'g', 'MarkerSize', 10);
xlim([1, 20]);

Exercise

x=linspace(1,2);
f=x.^2;
g=sin(2*pi.*x);
h=plot(x,f,'k-',x,g,'or');
title('Mini Assignment#1');
legend('t^{2}','sin(2\pit)');
xlabel('Time(ms)');
ylabel('f(t)');
set(h,'LineWidth',1.5,'MarkerFaceColor','m','MarkerSize',4);
set(gca,'FontSize',16);

多个图形

通过调用图形创建图形窗口

>> x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);
x = -10:0.1:10;
y1 = x.^2 - 8;
y2 = exp(x);
figure, plot(x,y1);
figure, plot(x,y2);

使用 gcf 句柄时要小心,gcf只能指向最后绘制的图形

指定图形位置和大小

>> figure('Position', [left, bottom, width, height]);

在一个图形中绘制多个图形

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

网格、框和轴的控制

grid 网格

box 边框

axis 坐标轴

将图形保存到文件中

saveas(gcf,'<filename','fileformat');

MATLAB初阶绘图相关推荐

  1. Matlab初阶绘图(2022b)

    Matlab初阶绘图(2022b) 绘图函数 plot( ) & others plot(x,y) plots each vector pairs (x,y) plot(y) plots ea ...

  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. 为什么excel图片会变成代码_莲藕为什么会变色?焯水就发黑,炖汤就变粉色,甚至会变成暗紫色...
  2. leetcode c程序总提示主函数_帅气中国小哥出“大招”,程序员跳槽面试刷题必备...
  3. C# 多线程并发锁模式-总结
  4. 【一周入门MySQL—2】单表查询
  5. 日常生活小技巧 -- 虚拟串口工具
  6. 案例:返回固定页面的http服务器
  7. for循环一种不常见的用法
  8. Java导出源程序_JAVA导出项目的所有源代码到一个文件
  9. 用自动化构建工具增强你的工作流程——gulp
  10. 分布式系统「伸缩性」大招之——「弹性架构」详解
  11. 《JavaScript菜鸟教程》学习
  12. linux fat get entry,操作系统--主引导程序控制权的转移
  13. Java岗史上最全八股文面试真题汇总,堪称2022年面试天花板
  14. 极虎病毒:虎年第一猛毒详解
  15. 那些超好听却不红的歌
  16. 秒杀排列组合(上)————排列篇
  17. 网易楚留香获取服务器信息,楚留香手游生活采集物有哪些 获取攻略
  18. Apache Superset 1.2.0教程 (二)——快速入门(可视化王者英雄数据)
  19. SF图像滤镜/美颜/美妆算法详解与实战
  20. 计算机的操作系统有哪些

热门文章

  1. 打开联想电脑管家的锁屏选项,导致系统出现蓝屏或闪退问题
  2. IO流(输入流与输出流)
  3. DRL经典论坛网络版 一人一句软件使用经验收集2
  4. 毕业论文知识点记录(三)——SPSS去相关
  5. 信号调理方法总结笔记
  6. 使用Linux挂载NAS硬盘的RAID分区
  7. 前端设计 响应式设计_响应设计简介
  8. 基于密码的移动办公安全能力体系构建
  9. Visual C++游戏编程基础之摩擦力、加速度、重力
  10. 【C#:WinForm+ADO.NET+SQL Server实现验证码登录】