Matlab %伍
第五章:初级绘图进阶
Special Plots
loglog
semilogx
semilogy
plotyy
hist
bar
pie
polar
Logarithm Plots
x = logspace(1,-1,100);
y = x.^2;
subplot(2,2,1);
plot(x,y);
title('Plot');
subplot(2,2,2);
semilogx(x,y); %横坐标取对数
title('Semilogx');
subplot(2,2,3);
semilogy(x,y); %纵坐标取对数
title('Semilogy');
subplot(2,2,4);
loglog(x,y); %全取对数
title('Loglog');
set(gca,'XGrid','on'); %给最后一个图的XGrid加坐标线
set(gca,'YGrid','on');
Y & Y
#在2020B版本中加入yyaxis函数创建具有两个YGrid的图
plotyy() %显示两个YGrid
EG(阻尼简谐运动):
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代表axis,为坐标轴;将y1的权柄赋予H1
set(get(AX(1),'Ylabel'),'String','Left Y-axis') %AX(1)代指左边y轴
set(get(AX(2),'Ylabel'),'String','Reft Y-axis') %AX(2)代指右边y轴
title('Labeling plotyy');
set(H1,'LineStyle','--');
set(H2,'LineStyle',':');
Histogram
y = randn(1,1000); %按正态分布的随机数
subplot(2,1,1);
title('Bins = 10');
subplot(2,1,2);
hist(y,50);
title('Bins = 50');
Bar Charts
x = [1 2 5 4 8];
y = [x;1:5]; %不同的组---[1 2 5 4 8];[1 2 3 4 5]
subplot(1,3,1);
bar(x);
title('A bargraph of vector x');
subplot(1,3,2);
bar(y);
title('A bargraph of vector y');
subplot(1,3,3);
bar3(y);
title('A 3D bargraph');
Stacked(堆叠式) and Horizontal(水平的)
x = [1 2 5 4 8];
y = [x;1:5];
subplot(1,2,1);
bar(y,'stacked');
title('Stacked');
subplot(1,2,2);
barh(y); %h = horizontal
%barh(y,'stacked') 水平堆叠式
title('Horizontal');
Pie Chart
a = [10 5 20 30];
subplot(1,3,1);
pie(a);
subplot(1,3,2);
pie(a,[0,0,0,1]);
subplot(1,3,3);
pie3(a,[0,0,0,1])
%更多关于pie自查
Polar Chart(极坐标)
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);
%自查意义(XP懒
Stairs and Stem Charts
x = linspace(0,4*pi,40);
y = sin(x);
subplot(1,2,1);
stairs(y); %阶梯图
subplot(1,2,2);
stem(y); %绘制离散序列数据
Boxplot and Error Bar
load carsmall
boxplot(MPG,Origin);
x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x));
errorbar(x,y,e); %e为误差条的长度
fill
fill()
eg:
t = (1:2:15)'*pi/8; %绘制点图
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');
%自行查询Text属性
EG:
t = (1:4)'*pi/2;
x = sin(t);
y = cos(t);
fill(x,y,'y');
axis square off;
text(0,0,'WAIT','Color','k','FontSize',60,...
'FontWeight','bold','HorizontalAlignment','center','LineWidth',1.5);
Color Space
[R G B];
%0 is minimum;1 is maximum;
White:FFFFFF=[255 255 255] %十六进制转换
Exercise:更换bar的一个条子的颜色{可自查Bar属性/Set}
G = [46 38 29 24 13];
S = [29 27 17 26 8];
B = [29 23 19 32 7];
h = bar(1:5,[G' S' B']); %按列分组1:5;
title('Medal count for top 5 countries in 2012 Olympics');
ylabel('Number of medals');
xlabel('Country');
legend('Gold','Silver','Bronze');
set(gca,'XTickLabel',...
{'USA','CHN','GBR','RUS','KOR'});
set(h(1),'facecolor',[1 0.8 0.2]);
set(h(2),'facecolor',[0.8 0.8 0.8]);
set(h(3),'facecolor',[0.8 0.4 0]);
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);
axis square;
xlabel('x');
ylabel('y');
colorbar&colormap([Name])
colorbar; %颜色变化
colormap([Name]);
%颜色变化
%可以看做:
a = ones(256,3);
colormap(a)
%自查colormap
3D Plots
plot3
surf
surfc
surface
meshc
contour
contourf
plot3()
EG1:
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');
EG2:
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t);
grid on;
axis square;
EG3:
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;
Surface
meshgrid() %组成网格
eg:
x = -2:1:2;
y = -2:1:2;
[X,Y] = meshgrid(x,y);
mesh() & surf()
eg:
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);
subplot(1,2,2);
surf(X,Y,Z);
contour()
eg:
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(2,1,1);
mesh(X,Y,Z);
axis square;
subplot(2,1,2);
contour(X,Y,Z);
axis square;
contour(Z,[-.45:.05:.45])
clabel()
contourf() %fill
eg:
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,[-.45:.05:.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()
eg:
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);
meshc(X,Y,Z);
subplot(1,2,2);
surfc(X,Y,Z);
view() & light()
eg:
sphere(50);
shading flat;
light('Position',[1 3 2]);
light('Position',[-3,-1,3]);
material shiny;
axis vis3d off;
set(gcf,'Color',[1 1 1]);
view(-45,20);
%调整角度
eg:
[X,Y,Z] = sphere(64);
h = surf(X,Y,Z);
axis square vis3d off;
reds = zeros(256,3);
reds(:,1) = (0:256.-1)/255;
colormap(reds);
shading interp;
lighting phong;
set(h,'AmbientStrength',0.75,'DiffuseStrength',0.5);
L1 = light('Position',[-1,-1,-1]);
%set(L1,'Position',[-1,-1,1]);
%set(L1,'Color','g');
patch()
eg:
v = [0 0 0;1 0 0;1 1 0; 0 1 0;0.25 0.25 1;...
0.75 0.25 1;0.75 0.75 1;0.25 0.75 1];
f = [1 2 3 4;5 6 7 8;1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8];
subplot(1,2,1);
patch('Vertices',v,'Faces',f,...
'FaceVertexCData',hsv(6),'FaceColor','flat');
view(3);
axis square tight;
grid on;
subplot(1,2,2);
patch('Vertices',v,'Faces',f,...
'FaceVertexCData',hsv(8),'FaceColor','interp');
view(3);
axis square tight;
grid on;
A professional graph
load cape
X = conv2(ones(9,9)/81,cumsum(cumsum(randn(100,100)),2));
surf(X,'EdgeColor','none','EdgeLighting','Phong',...
'FaceColor','interp');
colormap(map);
caxis([-10,300]);
grid off;
axis off;
%random graph,很好玩(赞)
Matlab %伍的更多相关文章
- Matlab 绘制三维立体图(以地质异常体为例)
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab slice方法和包络法绘制三维立体图
前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...
- Matlab 高斯_拉普拉斯滤波器处理医学图像
前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...
- MATLAB中绘制质点轨迹动图并保存成GIF
工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...
- linux下配置matlab运行环境(MCR)
在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...
- EMD分析 Matlab 精华总结 附开源工具箱(全)
前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...
- Atitit MATLAB 图像处理 经典书籍attilax总结
Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...
- Atitit MATLAB 图像处理attilax总结
Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...
- 使用MATLAB对图像处理的几种方法(下)
试验报告 一.试验原理: 图像点处理是图像处理系列的基础,主要用于让我们熟悉Matlab图像处理的编程环境.灰度线性变换和灰度拉伸是对像素灰度值的变换操作,直方图是对像素灰度值的统计,直方图均衡是对 ...
随机推荐
- svn 报 is not a working copy 错误
当时提交代码 svn 报 is not a working copy ,上网查找问题 要我重新拉代码下来 然后放进修改的代码重新提交,我觉得很不合理,我看了下我提交的代码文件有80多个,我在想是否 ...
- Finance财务软件(月度结转专题)
支持按模板结转 默认结转模板 1.结转收入 借: 6001 主营业务收入 6051 其他业务收入 6301 营业外收入 贷: 4103 本年利润 2.结转成本.费用和税金 借: 4103 本年利润 贷 ...
- 易语言json
1.易语言助手 ->网页功能->网页调试 打开post工具 提交协议头里面 右键可以自定义默认的十几个ua头 2.项目爬模发送数据格式为[{},{},{},{}] 相当于没有键 只有值 ...
- 397. 整数替换 (Medium
问题描述 397. 整数替换 (Medium) 给定一个正整数 n ,你可以做如下操作: 如果 n 是偶数,则用 n / 2 替换 n. 如果 n 是奇数,则可以用 n + 1 或 n - 1 替换 ...
- Java基础之标识符和关键字
关键字 标识符 Java所有的组成部分都需要名字.类名.变量名以及方法名都被称为标识符. Java 中标识符是为方法.变量或其他用户定义项所定义的名称.标识符可以有一个或多个字符. 标识符注意点: 在 ...
- Guava Retry重试机制
1.添加pom依赖 <dependency> <groupId>com.github.rholder</groupId> <artifactId>gua ...
- sql中exists用法
exists关键字介绍 exists强调的是 是否返回结果集,不要求知道返回什么,比如: SELECT * FROM AM_USER WHERE EXISTS (SELECT 1 FROM AM_RO ...
- 计算2-expr命令举例
一.expr命令 1.语法和功能 只能用于整数运算和字符串长度.匹配等运算处理 expr 2 + 2 expr 2 - 2 expr 2 \* 2 expr 2 / 2 i=5;i=`expr $1 ...
- Unity图集打包流程
1.先打开图集打包工具 设置为Always Enables(Legacy Sprite Packer) 打开地址Edit - ProjectSetting-Editor--Sprite Packer ...
- vite 路径别名 @ 配置
vite.config.ts resolve.alias 配置 const path = require('path'); import { defineConfig } from 'vite'; i ...