1.advanced 2D plots

  1. logspace(a,b,n)
    生成n个10^a到10^b个对数等距点
    (两极(10^a、10^b)取对数,再除n,得n个等距结果,再将这些结果取指数,指数的底为对数的底,得到n个等距点(等距点指取完对数之后等距,其本身不等距

x=logspace(-1,1,100);
y=x.^2;
subplot(2,2,1);
plot(x,y);
set(gca,'XGrid','on');%加网格
title('Plot');
subplot(2,2,2);
semilogx(x,y);
set(gca,'XGrid','on');%加网格
title('Semilogx');
subplot(2,2,3);
semilogy(x,y);
set(gca,'XGrid','on');%加网格
title('Semilogy');
subplot(2,2,4);
loglog(x,y);
title('Loglog');
set(gca,'XGrid','on');%加网格

  1. [AX,h1,h2]=plotyy(x,y1,x,y2)
x=0:0.01:20;
y1=200*exp(-0.05*x).*sin(x);
y2=0.8*exp(-0.5*x).*sin(10*x);
[AX,h1,h2]=plotyy(x,y1,x,y2);
[AX,h1,h2]=plotyy(x,y1,x,y2);
set(get(AX(1),'Ylabel'),'String','200*exp(-0.05*x)*sin(x)');
set(get(AX(2),'Ylabel'),'String','0.8*exp(-0.5*x)*sin(10*x)');
title('Labeling plotyy');
set(h1,'LineStyle','--');
set(h2,'LineStyle',':');
>>

  1. Histogram——直方图
function 功能
randn(row,col,lay) 生成由rowcollay个满足正态分布的随机数组成的array
randn(n) 生成n维matrix
randn(row,col) 生成row行,col列matrix
randn(1,col) 生成col维vector
y=randn(1,1000);
subplot(2,1,1);
hist(y,10);
title('Bins=10');
subplot(2,1,2)
hist(y,50);
title('Bins=50');

  1. bar chart
    bar(vector)
    bar(matrix)% bar(每一个向量)
    bar3(vector)
    bar3(matrix)
    bar(para,‘stacked’) %堆叠起来(栈)
    barh(para) %horizontal 水平
x=[1  2  5 4 8];
y=[x;1 2 3 4 5];
subplot(1,3,1);
bar(x);
subplot(1,3,2);
bar(y)
subplot(1,3,3);
bar3(y)

subplot(1,2,1);
bar(y,'stacked');
subplot(1,2,2);
barh(y);
subplot(1,3,1);
bar(y,'stacked');
subplot(1,3,2);
barh(y);
subplot(1,3,3);
barh(y,'stacked');

  1. pie chart
    pie(para) %,绘出每个元素所占比例(每个元素值/sum(元素))图
    pie3(para)
a=[10 10 5 30];
subplot(1,3,1);
pie(a);
subplot(1,3,2);
pie(a,[0,1,0,0]);%为1,则将其所在扇形弹开
subplot(1,3,3);
pie3(a,[0,1,0,0]);

  1. polar chart%相当于极坐标画图
    polar(theta,r)
    linspace(a,b,n)%生成由a到b的n个等距点
x=1:100;
theta=x/10;
r=log10(x);
subplot(1,4,1);
polar(theta,r);
theta=linspace(0,2*pi);
r=cos(4*theta);
subplot(1,4,2);
polar(theta,r);
theta=linspace(0,2*pi,6);
r=ones(1,length(theta));
subplot(1,4,3);
polar(theta,r);
theta=linspace(0,2*pi);
r=1-sin(theta);
subplot(1,4,4);
polar(theta,r);


练习:

>> theta=linspace(0,2*pi);
>> r=1+cos(theta);
>> subplot(3,1,1);
>> polar(theta,r);
>> r = 3*(1 + cos(theta));
>> subplot(3,1,2);
>> polar(theta,r);
>> r = 1-sin(theta);
>> polar(theta,r);
>> theta=linspace(0,2*pi,7);
>> r=ones(1,length(theta));
>> subplot(3,1,3);
>> polar(theta,r);

  1. stairs(y) stem(y)
>> x=linspace(0,4*pi,40);
>> y=sin(x);
>> subplot(1,2,1);
>> stairs(y);
>> subplot(1,2,2);
>> stem(y);

练习

t=linspace(0,10);
y=sin(pi*t.^2/4);
hold on;
stem(y);
plot(y);
hold off

  1. fill(x,y,str)
>> x=sin(t);
>> y=cos(t);
>> fill(x,y,'r');
>> axis square off;
>> text(0,0,'STOP','Color','w','FontSize',80,...
'FontWeight','bold','HorizontalAlignment','center');


练习:

t=(0:4)*pi/2;
x=sin(t);
y=cos(t);
fill(x,y,'y');
axis square off;
text(0,0,'WAIT','Color','K','FontSize',80,...
'FontWeight','bold','HorizontalAlignment','center');

2.Color space

  1. RGB

每个色系取值范围0~255,8位二进制表示,两个十六进制数表示
十六进制范围:000000~FFFFFF
十进制范围:[0 0 0]~[255 255 255]

所以数值从小到大,颜色从蓝到黄到红
颜色对照表
使用一个三维向量表示,各元素取值范围为0~1 (n/256)
范围:[0 0 0]~[1 1 1]

G=[46 38 29 24 13];
S=[29 27 17 26 8];
B=[29 23 19 32 7];
h=bar([G;S;B]);
h1=bar([G' S' B']);
title('Medal count for top5 countries in 2012 Olympics');
ylabel('Number of medals');
xlabel('Country');
legend('Gold','Silver','Bronze');
set(gca,'XTickLabel',{'USA','CHN','GBR','RUS','KOR'});
set(h1(1),'FaceColor',[1 0.84 0]);
set(h1(2),'FaceColor',[0.78,0.78,0.78]);
set(h1(3),'FaceColor',[0.54,0.27,0.15]);

  1. imagesc():用颜色表示数值
[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.^2+x.*y+y.^2;
surf(x,y,z);
box on;
set(gca,'FontSize',16);
zlabel('z');
xlim([-4 4]);
xlabel('x');
ylim([-4 4]);
ylabel('y');

imagesc(z);%三维变二维,用颜色表示z轴数
axis square;
xlabel('x');
ylabel('y');

colorbar;
%添加颜色柱,与imagesc同用

%matlab还有很多别的颜色图谱,可以按需要调节
colormap(jet);
colormap(hsv);
>>colormap(cool);
>> colormap(hot);
>> colormap(winter);
>> colormap(summer);
>> colormap(autumn);
>> colormap(spring);

3.3D plots

  1. plot3(x,y1,z1,str,x2,y2,z2,str…)
x=0:0.1:3*pi;
z1=sin(x);
z2=sin(2*x);
z3=sin(3*x);
y1=zeros(size(x));
y3=ones(size(x));
y2=y3./2;
plot3(x,y1,z1,'r',x,y2,z2,'b',x,y3,z3,'g');
grid on;
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
legend('y1','y2','y3');


练习:

t=0:pi/50:10*pi;
plot3(sin(t),cos(t),t);
grid on;
axis square

turns=40*pi;
t=linspace(0,turns,4000);
x=cos(t).*(turns-t)./turns;
y=sin(t).*(turns-t)./turns;
z=t./turns;
plot3(x,y,z);
grid on;


Line画图:x,y,z都是vector
face画图:x,y,z都是matirx(线动成面)

[X Y]=meshgrid(x,y)
将两个vector生成两个matrix
其中x在y方向上值不变
y在x方向上值不变

>> x=-2:1:2;
>> y=-2:1:2
>> [X,Y]=meshgrid(x,y);
>> XX =-2    -1     0     1     2-2    -1     0     1     2-2    -1     0     1     2-2    -1     0     1     2-2    -1     0     1     2>> YY =-2    -2    -2    -2    -2-1    -1    -1    -1    -10     0     0     0     01     1     1     1     12     2     2     2     2
  1. surface plot

mesh():网格
surf():填充颜色了的网格

x=-3.5:0.2:3.5;
y=-3.5:0.2:3.5;
[X,Y]=meshgrid(x,y);
Z=X.*exp(-X.^2-Y.^2);
subplot(1,2,1);
mesh(X,Y,Z);
axis square;
subplot(1,2,2);
surf(X,Y,Z);
axis square;

function 功能
contour(X,Y,Z) 类似于投影 等价于[C,h]=contour(Z);
contour(Z,[a:d:b]) 设置z值间距
clabel(C,h) 加上数据标签
contourf(Z) 填上颜色fill

x=-3.5:0.2:3.5;
y=-3.5:0.2:3.5;
[X,Y]=meshgrid(x,y);
Z=X.*exp(-X.^2-Y.^2);
subplot(1,3,1);
contour(Z,[-0.45:0.05:0.45]);
axis square;
subplot(1,3,2);
[C,h]=contour(Z);
clabel(C,h);
axis square;
subplot(1,3,3);
contourf(Z);
axis square;


meshc() surfc()
在mesh() 和surf()的基础上,下面画上contour

matlab06-进阶绘图相关推荐

  1. MATLAB教学_06进阶绘图

    本文学习视频:https://www.bilibili.com/video/av68228488?p=6 本文学习内容: 进阶2D绘图 绘图空间 3D绘图 semilogx(x,y); %x轴取对数 ...

  2. 【MATLAB】进阶绘图 ( colormap 颜色图矩阵分析 | 自定义 colormap 颜色图 | 生成 64 x 3 的 colormap 颜色图矩阵 )

    文章目录 一.colormap 矩阵分析 二.自定义 colormap 颜色图 1.生成 colormap 矩阵 2.代码示例 一.colormap 矩阵分析 imagesc 函数参考文档 : htt ...

  3. 【MATLAB】进阶绘图 ( Boxplot 箱线图 | boxplot 函数 | Error Bar 误差条线图 | errorbar 函数 )

    文章目录 一.Boxplot 箱线图 1.boxplot 函数 2.代码示例 二.Error Bar 误差条线图 1.errorbar 函数 2.代码示例 一.Boxplot 箱线图 1.boxplo ...

  4. 【MATLAB】进阶绘图 ( Bar 条形图 | bar 函数 | bar3 函数 | Bar 条形图样式 | 堆叠条形图 | 水平条形图 | barh 函数 )

    文章目录 一.Bar 条形图 1.bar 函数 2.矩阵数据表示 3.bar 函数代码示例 二.Bar 条形图样式 1.bar 函数样式 2.堆叠条形图示例 三.水平条形图 1.barh 函数 2.代 ...

  5. 【安卓深度控件开发(2.2)】LCDView - 进阶绘图

    为什么80%的码农都做不了架构师?>>>    <h2>阅读前题</h2> <p>阅读本节之前需要先阅读<a href="http ...

  6. Python数据分析-绘图-2-Seaborn进阶绘图-6-回归图

    一.regplot 函数:seaborn.regplot 常用参数: x,y array,str,series,如果是字符串应该是data中对应的属性名,使用series将会在轴上显示名称. data ...

  7. Matlab进阶绘图第8期—聚类/分类散点图

    聚类/分类散点图是一种特殊的特征渲染散点图. 聚类/分类散点图通过一定的聚类.分类方法,将特征相近的离散点划分到同一个类别中,进而将每个离散点赋予类别标签,并利用不同的颜色对不同的类别进行区分. 本文 ...

  8. 【MATLAB】进阶绘图 ( Pie Chart 饼图 | pie 函数 | 三维饼图 | pie3 函数 )

    文章目录 一.Pie Chart 饼图 1.pie 函数 2.pie3 函数 3.饼图示例 一.Pie Chart 饼图 1.pie 函数 pie 函数文档 : https://ww2.mathwor ...

  9. Android高级进阶——绘图篇(五)setXfermode 设置混合模式

    一.GPU硬件加速 1.概述 GPU英文全称Graphic Processing Unit,中文翻译为"图形处理器".与CPU不同,GPU是专门为处理图形任务而产生的芯片. 在GP ...

  10. Matlab进阶绘图第4期—三维堆叠柱状图/三维堆积图

    三维堆叠柱状图是堆叠图(见Matlab论文插图绘制模板第6期)在三维空间的拓展. 三维堆叠柱状图不仅可以直观地展示各部分总数的对比,还能够看出各部分在总数中所占的比例,从而使数据更加形像. 当然,三维 ...

最新文章

  1. 计算机应用基础word表说课,制作word表格说课课件.ppt
  2. 空值排序(oracle/sqlserver)
  3. CF572_Div2_D2
  4. qgraphicsitem 复制副本_如何在pyqt5中复制粘贴Qgraphicsitem?
  5. Python学习--环境搭建
  6. Linux 文件目录特殊权限设定(SUID,SGID,SBIT)
  7. 如何通过 C# 动态备份 Sql 数据库?
  8. el-select回显
  9. Ubuntu10.10的网络配置
  10. 1元解锁 | Python万能代码模板 |10大必学实用技巧
  11. excel 两列数据怎么把组合的可能全部做出来?
  12. Google的语音识别API,支持各种语言
  13. 088、Docker 如何支持多种日志方案 (2019-05-10 周五)
  14. Postfix邮件服务系统
  15. 数据抓包+hijson
  16. 如何解决下载慢的大问题,如neo4j等
  17. DIOR数据集转COCO格式 paddlepaddle
  18. 使用SVG.Net生成svg格式文字图片
  19. 车辆动力学知识总结(三) 二自由度动力学模型
  20. MOOC战德臣数据库课程自用笔记_3_关系模式之关系代数

热门文章

  1. php+yii框架,php配置yii框架(转)
  2. BigData JAQ入门
  3. 鬼脚七:淘宝卖家需知的搜索知识(上)
  4. 【华为OD统一考试B卷 | 200分】宜居星球改造计划(Java JavaScript Python)
  5. 掌握随机森林:基于决策树的集成模型
  6. aws iam_使用策略哨兵在AWS IAM中自动执行Salesforce云安全性的最小特权
  7. Eigen库中的Identity()函数作用
  8. 卸载掉夸克后,我安装了这款浏览器,惊喜满满
  9. 新库上线 | CnOpenData全球摩天大楼数据
  10. 机器人独立关节PD控制(控制小白入门)