[Matlab科学绘图] Matlab三维绘图总结

article/2025/9/28 21:17:56

主要对matlab三维绘图函数进行总结并展示一下绘图结果,重点不在函数解读,在于函数介绍,函数的具体使用可以查看matlab的help文档。

函数名说明
line,plot3,ezplot3绘制三维曲线
mesh,ezmesh绘制三维网状图
meshc,ezmeshc绘制带有等高线的三维网状图
meshz绘制带有“围裙”的网状图
surf,ezsurf绘制三维曲面图
surfc,ezsurfc绘制带有等高线的三维曲面图
surfl绘制带有光照的三维曲面图
surfnorm计算或者显示三维表面法向
contour3绘制三维等高线图
waterfall绘制带有水流效果的三维图
pcolor绘制以颜色表示高度的图形

1. line,plot3,ezplot3绘制三维曲线

t=linspace(0,pi,401); %生成图形窗口
xf=inline('sin(t*8)*2'); %生成内联函数
yf=inline('cos(t*8)*3');
s(1)= subplot(131);
%利用函数line绘制三维曲线
line(sin(t*8),cos(t*8),t);
s(2)=subplot(132);
%利用plot3绘制两条曲线
plot3(sin(t*8)/2,cos(t*8)/2,t,'k',sin(t*16),cos(t*16),t,'r:');
s(3)=subplot(133);
%根据符号表达式绘制三维曲线
ezplot3(xf,yf,inline('t'),[-3,3]);
axis equal;
%设置坐标轴视角
view(s(1),[-33,14]);
view(s(2),[-33,14]);
view(s(3),[44,62]);

2.mesh绘制三维网格图

[X,Y]=meshgrid(-2:0.2:2, -2:0.2:2);%生成坐标格网矩阵
Z=X.*exp(-X.^2-Y.^2);
subplot(131);mesh(X,Y,Z);%绘制网状图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132);mesh(X,Y,Z,rand(size(Z)));%绘制随机彩色网状图
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133);mesh(X,Y,Z,2*ones(size(Z)),'EdgeColor','k');%绘制单色网状图
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

3.ezmesh绘制三维网格图

zfun=inline('sqrt(1-s^2-t^2)');%定义内联函数
xs=inline('cos(s)*cos(t)');
ys=inline('cos(s)*sin(t)');
zs=inline('sin(s)');
subplot(131);ezmesh(zfun,100);%绘制网状图并指明采样点数
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132);ezmesh(zfun,[-1,1],20);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133);ezmesh(xs,ys,zs,[-pi,pi],20);
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

改变ezmesh绘制网状图的着色方案

xs=inline('cos(s)*cos(t)');
ys=inline('cos(s)*sin(t)');
zs=inline('sin(s)');
subplot(131);ezmesh(xs,ys,zs,[0,pi],16);
view([-39,56])
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132);ezmesh(xs,ys,zs,[0,pi],16);
view([-39,56])
S1=get(gca,'Children');
set(S1,'CData',rand(size(get(S1,'CData'))));%通过句柄对网状图着色
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133);ezmesh(xs,ys,zs,[0,pi],16);
view([-39,56])
S1=get(gca,'Children');
set(S1,'EdgeColor','k');%通过句柄对网状图着色
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

5.meshc绘制带有等高线的网状图

[X,Y,Z]=peaks(30);%生成坐标数据
subplot(121),meshc(Z);%生成带等高线的网状图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),m=meshc(X,Y,Z,Z);
set(m(1),'EdgeColor','k');%通过句柄改变属性
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

6.ezmeshc绘制带有等高线的网状图

subplot(131),ezmeshc('imag(atan(x+i*y))',[-4,4]);
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132),ezmeshc('real(log(x+i*y))',[-4,4],30);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
S2=get(gca,'Children');set(S2(end),'EdgeColor','k');
subplot(133),ezmeshc('real(log(x+i*y))',[-4,4],'circ');
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

7.meshz绘制带有“围裙”的网状图

[X,Y,Z]=peaks(30);%生成坐标数据
subplot(121),meshz(Z);%生成带"围裙"的网状图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),m=meshz(X,Y,Z,Z);
set(m(1),'EdgeColor','k');%通过句柄改变属性
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

8.surf绘制三维曲面图

[x,y]=meshgrid(linspace(-3,3,31));%生成格网坐标
z=(x-y).*exp(-(x.^2+y.^2)/2);
subplot(121),surf(x,y,z);%绘制曲面图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),surf(x,y,z,'EdgeColor','flat');
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

9.ezsurf根据数学表达式绘制三维曲面

funx=inline('sin(s)*t');%定义数学表达式
funy=inline('cos(s)*t');
funz=inline('sinc(t)');
subplot(231),ezsurf(@(x,y) funz(x)*cos(y));%绘制曲面图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(232),ezsurf(@(x,y) sin(x*2)*sinc(y),[-pi,pi]);%绘制曲面图,并设定网格线属性
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(233),ezsurf(funx,funy,funz);%绘制曲面图,并设定网格线属性
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');
subplot(234),ezsurf(@(s,t) funx(s,t)*sin(t),@(s,t) funy(s,t)*cos(t^2),...@(s,t) funz(t)*sinc(s),[-2,2]);%绘制曲面图,并设定网格线属性
xlabel('(d)','Fontsize',14,'Fontname','Times New Roman');
subplot(235),ezsurf(@(s,t) funz(t)*sin(s),30);%绘制曲面图,并设定网格线属性
xlabel('(e)','Fontsize',14,'Fontname','Times New Roman');
subplot(236),ezsurf(@(s,t) exp(-[s^2+t^2]),[-2,2],2,'circ');%绘制曲面图,并设定网格线属性
xlabel('(f)','Fontsize',14,'Fontname','Times New Roman');

10.surfc绘制带有等高线的曲面

[x,y]=meshgrid(linspace(-4,4,30));%生成采样数值点
z=3*(x-1).^2.*exp(-x.^2-(y-1).^2)-8*(x/5-x.^3-y.^5).*exp(-x.^2-y.^2)-...1/4*exp(-(x+1).^2-y.^2);
subplot(121),surfc(x,y,z);%绘制三维曲面
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),surfc(x,y,z,'EdgeColor','k','FaceColor','None');%设置曲面颜色属性
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

ezsurfc绘制带有等高线的曲面

subplot(121)
ezsurfc(@(x,y)sin(x)*exp(-x.^2-y.^2));
subplot(122)
ezsurfc(@(x,y)sin(2*y)*exp(-x.^2-y^2/2),[-2,2],'circ');
view([-111,42])

11.surfl绘制带有光照效果的曲面

[x,y,z]=peaks(30);
subplot(121),surfl(x,y,z);
shading interp;%着色淡化处理
colormap(gray);
axis([-3,3,-3,3]);view(3);%设置颜色为灰度、坐标轴范围和视角
subplot(122)
surfl(x,y,z,[0.8,0.2,0.8],'light');%带有光照效果
shading interp;
axis([-3,3,-3,3]);view(3);

12.surfnorm计算或者显示三维表面法向

[X,Y,Z]=peaks(40);
surfnorm(X,Y,Z);xlim([-3,3]);ylim([-3,3]);

13.contour3绘制三维等高线

subplot(121),contour3(peaks(40));%绘制三维等高线
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),mesh(peaks(40),'EdgeColor',[0.85,0.85,0.85]);%绘制三维网状曲面,并设置网格线为浅灰色
hold on
contour3(peaks(40));
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

14.waterfall绘制具有流水效果的的曲面,瀑布图

[x,y,z]=peaks(40);
subplot(131),waterfall(peaks(40));%绘制具有流水效果的曲面
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132),waterfall(peaks(40),rand(40));%绘制具有流水效果的曲面
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133),w=waterfall(x',y',z');%绘制具有流水效果的曲面
set(w,'EdgeColor','k');
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

15.pcolor绘制以颜色表示高度值的图形

[x,y,z]=peaks(20);
subplot(131),pcolor(x,y,z);%伪色绘图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132),p=pcolor(x,y,z);
set(p,'EdgeColor','flat');%除去网格线
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133),hi=image(z);
set(hi,'CDataMapping','scaled');%设置颜色映像属性
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');
set(gca,'YDir','normal');

16.曲面切割效果

水平方向切割

[x,y,z]=peaks(800);
subplot(131),surf(x,y,z);shading interp;
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
z(z>4)=2;
z(z<-4)=-4;
subplot(132),surf(x,y,z);
view(-48,52);shading interp;
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133),surf(x,y,-z);
view(-48,52);shading interp;
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

任意切割

[x,y,z]=peaks(200);
z1=z;
z1(x<0&y>0)=nan;%利用NaN切割曲面
z2=z;
z2(sqrt(x.^2+y.^2)<1.2)=nan;
subplot(131),surf(x,y,z);
shading interp;
xlim([-3,3]);ylim([-3,3]);
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132),surf(x,y,z1);
shading interp;
xlim([-3,3]);ylim([-3,3]);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133),surf(x,y,z2);
shading interp;
xlim([-3,3]);ylim([-3,3]);
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

17.cylinder生成关于z轴旋转对称的螺旋体坐标

r=2+cos(linspace(0,pi*2));%生成半径向量
[x1,y1,z1]=cylinder(r);%生成螺旋体坐标
[x2,y2,z2]=cylinder(r,30);
subplot(131),cylinder(r);%生成三维螺旋体
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(132),surf(x1,y1,z1);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');
subplot(133),mesh(x2,y2,z2);
xlabel('(c)','Fontsize',14,'Fontname','Times New Roman');

18.sphere生成单位球体坐标

[x,y,z]=sphere;
subplot(121),sphere;
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),surf(x,y,z);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

19.slice绘制三维切片图

[x,y,z]=meshgrid(-2:0.2:2,-2:0.25:2,-2:0.16:2);
v=x.*exp(-x.^2-y.^2-z.^4);
[xi,yi]=meshgrid(-2:0.1:2);
zi=6*exp(-[xi.^2+yi.^2]).*xi;%计算完全切面轴坐标
zi(zi>1)=1;zi(zi<-1)=-1;%限制zi取值范围
subplot(121),slice(x,y,z,v,[-1.2 0.8 2],2,[-2 -0.2]);%绘制切片图
xlabel('(a)','Fontsize',14,'Fontname','Times New Roman');
subplot(122),slice(x,y,z,v,zi,xi,yi);
xlabel('(b)','Fontsize',14,'Fontname','Times New Roman');

参考文献

刘正君.《MATLAB科学计算与可视化仿真宝典》

 


http://chatgpt.dhexx.cn/article/ebncLtbS.shtml

相关文章

使用MATLAB进行三维空间绘图

目录 使用MATLAB进行三维空间绘图一个入门例程matlab中的mesh()函数matlab中的meshgrid()函数matlab中的plot3函数例程代码解释 使用MATLAB进行三维空间绘图 三维图具有直观、立体的空间形象&#xff0c;容易使人形成总体的比较具体的三维印象&#xff0c;接近于现实.所以 对某…

Matlab三维散点绘图

有两种方式可以实现对散点集的三维绘图 1.scatters函数 散点图 - MATLAB scatter- MathWorks 中国 s ones(max(size(z)),1)*20; %圆圈的大小 scatter3(x,y,z,s,z,filled,s); %filled表示填充圆圈 2.三维插值mesh函数 首先对散点集进行三维插值&#xff0c;使用scatteredIn…

MATLAB三维绘图---三维曲面图

matlab绘制三维图中&#xff0c;最常见的是三维曲线图和三维曲面图 三维曲线图比较简单函数命令为plot3&#xff0c;已经详细介绍过&#xff0c;具体请见Matlab三维绘图------三维曲线图 三维曲面图的不同类型及对比 三维曲面图又分为三维网面和三维网格面图&#xff0c;其原…

matlab三维向量,matlab三维数据绘图

 3D数据绘制唇部图像主要由两部分构成,一个是唇部在X-Y平面的栅格,一个是根据相应Z轴的涂色。主要使用了matlab里meshgrid、surf和shading。 1 使用meshgrid生成栅格 meshgrid(x,y)由向量x和向量y通过复制的方法产生绘制图形时所需的栅格数据点矩阵X、Y。该命令产生栅格数…

matlab 三维绘图

clear,clc; x0:pi/10:2*pi; yx; [X,Y]meshgrid(x,y);%转换为空间点坐标 Zsin(X).sin(2X3); surf(X,Y,Z) box on xlabel(‘x轴’),ylabel(‘y轴’),zlabel(‘z轴’) title(‘三维曲面图’) grid on 绘制同心圆 fcs.m ainput(‘输入横坐标:’); binput(‘输入纵坐标:’); rinput…

matlab三维绘图注释,Matlab三维绘图与图形处理

三维绘图 01 空间曲线作图 调用格式为: plot3(x,y,z,s) 若x,y,z是同维数的向量,则表示绘制一条横坐标为x,纵坐标为y,函数值为z的一条空间曲线,若x,y,z为mn矩阵,则绘制n条空间曲线,s’指定曲线的类型(颜色、线型、点标记等)。 实践 在区间[0,8π \piπ]绘制参数曲线x=sint…

MATLAB三维绘图

目录 1 三维绘图 1.1 绘制三维曲线图 1.2 绘制三维曲面图 2 图形编辑器 1 三维绘图 1.1 绘制三维曲线图 与二维绘图类似&#xff0c;三维绘图调用的是plot3函数 示例代码&#xff1a; x -10:0.1:10; %x轴 y -10:0.1:10; %y轴 z x 2*y; %z轴 plot3(x,y,z); 运…

MATLAB 绘制三维图 | 附多个实例

文章目录 情形一&#xff1a;函数有显式表达式 z f ( x , y ) zf(x,y) zf(x,y) 主要使用函数&#xff1a;meshgrid,mesh,fmesh情形三&#xff1a;函数表达式不含有 z z z 主要使用函数&#xff1a;meshgrid,isosurface在这里插入图片描述 情形3&#xff1a;函数有参数表达式…

【MATLAB】三维绘图 ( 三维绘图步骤 )

文章目录 一、绘制三维图像1、三维绘图步骤2、代码示例 二、双峰函数 一、绘制三维图像 1、三维绘图步骤 定义 x , y , z x,y,z x,y,z 轴变量 , % z 轴元素列举 % 从 0 开始 , 每次递增 pi / 100 , 到 4 * pi 结束 z 0: pi / 100 : 4 * pi;% 定义 x 变量 % 使用 sin 函数 ,…

matlab绘图(三)绘制三维图像

目录 一、绘制三维曲线 二、绘制三维曲面 1.meshgrid函数 2.mesh和surf函数 一、绘制三维曲线 1.最基本的绘制三维曲线的函数—plot3 plot3(x1,y1,z1, 选项 1,x2,y2,z2, 选项 2,…, xn,yn,zn , 选项 n) 其中&#xff0c;每一组 x &#xff0c; y &#xff0c; z 组成一组曲线…

MATLAB三维绘图命令plot3入门

一、引言 Matlab软件提供了强大的可视化功能&#xff0c;既可以绘制平面图形&#xff0c;也可以绘制三维图形。绘制三维曲线图或者散点图可以使用命令plot3来实现。本文给出利用plot3绘制三维曲线图&#xff08;其实就是曲面&#xff09;或者散点图入门简介。 二、plot3基本用法…

使用MATLAB进行三维图像绘制

一、mesh 绘制无线网格网络图 其中x是n维向量&#xff0c;y是m维向量&#xff0c;z是m*n维向量 除了mesh函数meshc函数还能在xy平面上绘制曲面的等高线&#xff0c;meshz函数还能在xy平面上绘制曲面的底座 mesh(x,y,z) x1:0.1:10; y1:0.1:10; [x,y] menshgrid(x,y); zx.^2-…

股票APP UI界面设计

金融类型股票APP UI界面设计 实时动态查询 股票市场应用iOS UI套件。可以在多个屏幕上自定义您的交易环境。具有资产类别和细分市场的全套交易工具和功能。可以选择市场&#xff0c;工具&#xff0c;图表和交易组件来定制您自己的股票交易app。 模板以蓝色为主色调&#xff0…

Python - PyQT5开发UI界面 - 环境搭建

没有做过UI界面的都会把UI的制作想象的很神秘&#xff0c;我在刚开始的时候也是感觉异常神秘、很复杂、并且无从下手&#xff0c;不过在真正的做出来一个界面后&#xff0c;发现也并没有想象中的那么难&#xff0c;而且做出来可视化的东西所带来的成就感是超越代码本身的&#…

19个免费的UI界面设计工具及资源

原文&#xff1a;http://www.oschina.net/news/16602/19-free-ui-design-tools-toolkits-and-resources-for-designers 开源中国社区刚发布了一篇《21个免费的UI界面设计工具、资源及网站》&#xff0c;介绍了免费的Web UI、移动UI、线框工具等。作为该文章的续篇&#xff0c;本…

实验一 基本 UI 界面设计

实验一 基本 UI 界面设计 【实验目的】 1.熟悉 Android Studio 开发工具操作 2.熟悉 Android 基本 UI 开发&#xff0c;并进行 UI 基本设计 【实验内容】 实现如下 Android 应用&#xff0c;实现如下显示效果&#xff08;暂无控件点击事件效果&#xff09;&#xff1a; …

QT多个ui界面设计

这里以2个ui界面为例 新建一个设计关联ui背景设计 新建一个设计 在已有一个项目和ui的时候&#xff0c;右键Forms&#xff0c;在出来的的菜单中&#xff0c;点击Add New&#xff0c;弹出的界面选择Qt Designer From Class&#xff0c;如下。 单击choose后&#xff0c;弹出以下…

QT项目界面文件(.ui)设计和运行机制

后缀为“.ui”的文件是可视化设计的窗体的定义文件,如 widget.ui。双击项目文件目录树中的文件 widget.ui,会打开一个集成在 Qt Creator 中的 Qt Designer【ui设计器】 对窗体进行可视化设计 组件面板:窗口左侧是界面设计组件面板,分为多个组,如Layouts、Buttons、Displ…

Android studio - UI 界面设计(仿问卷星登陆注册界面)

1 先上效果图&#xff1a; 2 准备工作 建如下活动文件以及素材文件 3 代码实现 3.1 修改themes.xml、 themes.xml(night)文件 使自定义按钮组件起效果 在框出区域加 .Bridge 两个 xml 文件都要加**自定义按钮的应用**代码实现 btn_login.xml <?xml version"1.0&quo…

Element ui后台管理系统界面设计

自己学了一点Element ui前端框架&#xff0c;然后尝试设计了几个页面&#xff0c;仅供学习参考&#xff01;