5.4 绘制数据图

 参考视频: 5 - 4 - Plotting Data (10 min)

5.4.1 绘制曲线

  1、画一个sin曲线
 >> t = [:0.01:0.98];
>> y1 = sin( * pi * * t);
>> plot(t,y1);

  2、画一个cos曲线

 >> y2 = cos( * pi *  * t);
>> plot(t,y2);

3、将两个曲线合并在一起
 >> plot(t,y1);
>> hold on
>> plot(t,y2,'r');

4、给图像添加信息
 > xlabel('time')    % X轴标签
>> ylabel('value')   % Y轴标签
>> legend('sin','cos')  % 添加曲线名称
>> title('my plot')  % 添加标题

5、保存到文件
 >> print -dpng 'myPlot.png'
>> ls
Directory of D:\myc_learn\machine_learning\code\week2
[.] .m hello.dat myPlot.png
[..] featuresX.dat hello.txt priceY.dat
>> close
6、绘制多张图

   绘制多张图,需要指定将哪个曲线放在哪个图中。否则会一直绘制在当前窗口,覆盖之前的图形

 >> figure(); plot(t,y1);  % 在figure1中绘制
>> figure(); plot(t,y2); % 在figure2中绘制
7、将两个图显示在一张图片中
 >> subplot(,,);  % 将图片划分为两个格子,访问第一个格子
>> plot(t,y1)    % 画第一个图像
>> subplot(,,); % 访问第二个格子
>> plot(t,y2)    % 画第二个图像

8、改变坐标轴范围
 >> axis([0.5  - ])

  点击一下第一张图片,再运行一下上面那行代码,图变为:

9、清空和关闭图片
 >> clf    % 清空
>> close   % 关闭

5.4.2 绘制可视化矩阵

1、生成矩阵图

  根据矩阵的值生成图像,不同的颜色对应矩阵中不同的值

 >> A = magic()
A = >> imagesc(A)

2、显示颜色条
 >> colorbar

  或者直接使用下面的一行代码:

 >> imagesc(magic(5)), colorbar;
3、生成灰度图
 >> imagesc(A), colorbar, colormap gray;

  生成一个15行15列灰度图

 >> imagesc(magic()),colorbar,colormap gray;

  以 imagesc(magic(15)),colorbar,colormap gray; 为例。

  这种几个逗号隔开的命令一起运行的方式,叫做逗号连接函数调用 comma chaining of function calls 或 comma chaining commands 。

  比如赋值操作可以写成:a=1, b=2, c=3;

5.4.3 散点图

   plot(x,y,'rx', 'MarkerSize', );
xlabel('Population of City in 10,000s');
ylabel('Profit in $10,000s');
title('POPULATION AND PROFIT');

  图像绘制在Octave官方文档的 15.2.1 Two-Dimensional Plots ,图形属性设置在15.3.3.4 Line Properties。

如果想设置某个属性,直接写属性名,后面跟一个值。plot (x, y, property, value, …)

  例如  plot (x, y, 'linewidth', 2, …);

【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 5 Octave Tutorial—5.4 绘制数据图的更多相关文章

  1. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 5 Octave Tutorial

    Lecture 5 Octave教程 5.1 基本操作 Basic Operations 5.2 移动数据 Moving Data Around 5.3 计算数据 Computing on Data ...

  2. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 5 Octave Tutorial—5.6 向量化 Vectorization

    5.6 向量化 Vectorization 参考视频: 5 - 6 - Vectorization (14 min).mkv 下面是向量化的小例子,如果将所有u(j) .所有v(j).所有w(j)都看 ...

  3. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 5 Octave Tutorial—5.5 控制语句: for, while, if 语句

    5.5 控制语句: for, while, if 语句 参考视频: 5 - 5 - Control Statements_ for, while, if statements (13 min).mkv ...

  4. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 15—Anomaly Detection异常检测

    Lecture 15 Anomaly Detection 异常检测 15.1 异常检测问题的动机 Problem Motivation 异常检测(Anomaly detection)问题是机器学习算法 ...

  5. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 16—Recommender Systems 推荐系统

    Lecture 16 Recommender Systems 推荐系统 16.1 问题形式化 Problem Formulation 在机器学习领域,对于一些问题存在一些算法, 能试图自动地替你学习到 ...

  6. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 14—Dimensionality Reduction 降维

    Lecture 14 Dimensionality Reduction 降维 14.1 降维的动机一:数据压缩 Data Compression 现在讨论第二种无监督学习问题:降维. 降维的一个作用是 ...

  7. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 13—Clustering 聚类

    Lecture 13 聚类 Clustering 13.1 无监督学习简介  Unsupervised Learning Introduction 现在开始学习第一个无监督学习算法:聚类.我们的数据没 ...

  8. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 12—Support Vector Machines 支持向量机

    Lecture 12 支持向量机 Support Vector Machines 12.1 优化目标 Optimization Objective 支持向量机(Support Vector Machi ...

  9. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 11—Machine Learning System Design 机器学习系统设计

    Lecture 11—Machine Learning System Design 11.1 垃圾邮件分类 本章中用一个实际例子: 垃圾邮件Spam的分类 来描述机器学习系统设计方法.首先来看两封邮件 ...

随机推荐

  1. flash代码

    Flash常用的动作命令一.Flash中的常用命令:1.在当前帧停止播放 on(release){ stop();} 2.从当前帧开始播放 on(release){ play();} 3.跳到第 10 ...

  2. NODE 性能优化

    五个手段 “如果你的 node 服务器前面没有 nginx, 那么你可能做错了.”—Bryan Hughes Node.js 是使用 最流行的语言— JavaScript 构建服务器端应用的领先工具 ...

  3. CRC-16校验原理

    最详细易懂的CRC-16校验原理(附源程序) 1.循环校验码(CRC码): 是数据通信领域中最常用的一种差错校验码,其特征是信息字段和校验字段的长度可以任意选定. 2.生成CRC码的基本原理: 任意一 ...

  4. 【Android】Android 学习记录贴

    官网 教程学习笔记 Genymotion 安卓虚拟器太慢,用Genymotion(装载eclipse的插件) 利用Genymotion运行Android应用程序 1.首先,点击 来启动或者创建您要使用 ...

  5. [leetcode]_Binary Tree Level Order Traversal I && II

    题目:给定一棵二叉树,对其进行层次遍历,将遍历结果存入二维链表中. 思路:二叉树的层次遍历关键在于使用Queue. 复习: Queue的定义.LinkedList实现了Queue接口,因此可用Link ...

  6. ASP.NET 线程详解

    本文是博主翻译文章,估计会省略一些,但是我尽量能翻译好,各个知识点通俗易懂.译文如下: ASP.NET Thread Usage on IIS 7.5, IIS 7.0, and IIS 6.0 我简 ...

  7. HTTP 和 SOAP

    http:是一个客户端和服务器端请求和应答的标准(TCP).http协议其目的是为了提供一种发布和接收htttp页面的方法 一http协议的客户端与服务器的交互:由HTTP客户端发起一个请求,建立一个 ...

  8. UVA10652 Board Wrapping

    题意 PDF 分析 就是一个裸的凸包. 如何确定点?就用中心向四边连垂直的向量然后旋转,加上中心点,即可得出旋转后的点. 时间复杂度\(O(T n \log n)\) 代码 #include<i ...

  9. django的表与表之间的关系详细讲解

    转:http://www.cnblogs.com/feixuelove1009/p/5855295.html

  10. python SQLAlchemy自动生成models文件

    1.安装SQLAcodegen pip install sqlacodegen 2.执行 sqlacodegen mysql://root:123456@127.0.0.1:3306/test > ...