当前位置:网站首页>MATLAB三维绘图命令plot3入门
MATLAB三维绘图命令plot3入门
2022-08-04 00:14:00 【杨老头软工】
一、引言
Matlab软件提供了强大的可视化功能,既可以绘制平面图形,也可以绘制三维图形。绘制三维曲线图或者散点图可以使用命令plot3来实现。本文给出利用plot3绘制三维曲线图(其实就是曲面)或者散点图入门简介。
二、plot3基本用法详述
基本语法:plot3(x, y, z, s )
其中x、y和z是同维数的数组,(x,y)构成了三维曲面图形在定义域上的坐标点,z是竖坐标,可以是(x,y)的函数,也可以只有数值关系。
s是图元属性。
其功能是根据根据属性s给定的颜色或者线元和曲面上的网格点(x, y, z)绘制空间曲面的曲线图。
图元属性s均可以缺省。当缺省s的时候,用系统自动指定的颜色绘制三维曲线图;
例1.已知横坐标和纵坐标网格,绘制空间曲线图。
%示例代码(1)利用系统给定颜色绘图
[x,y]=meshgrid(-2*pi:0.2:2*pi);
z=(x.^2-2*x).*exp(-x.^2-y.^2-x.*y);;
plot3( x, y, z );
%运行结果
%示例代码(2):指定颜色
[x,y]=meshgrid(-2*pi:0.2:2*pi);
z=(x.^2-2*x).*exp(-x.^2-y.^2-x.*y);
plot3( x, y, z, 'r' )
%运行结果
%示例代码(3):每条线都根据自己的需要指定颜色
[x,y]=meshgrid(-2*pi:0.2:2*pi);
z=(x.^2-2*x).*exp(-x.^2-y.^2-x.*y);
len = length( z );
for i = 1 : len
plot3( x(:,i), y(:,i), z(:,i), 'color', [ i/(len), (i+len)/(3*len), (i+len)/(6*len) ])
hold on
end
%运行结果
例2:绘制螺旋线图(虚线)
参考代码:
clear all
clc
t = [ 0 : 0.02 : 10 ] * pi;
r = 2;
x = r * cos(t);
y = r * sin(t);
z = 0.5 * t;
plot3( x, y, z, 'b--' )
%运行结果
例3:绘制随机散点图
参考代码:
clear all
clc
[ x, y ] = meshgrid( 0 : 0.2 : 3 );
z1 = randn( size(x) );
plot3( x, y, z1, 'ro' )
hold on
[ x, y ] = meshgrid( 1 : 0.2 : 4 );
z2 = randn( size(x) ) + 2;
plot3( x, y, z2, '.', 'markersize', 20 )
xlabel('x');
ylabel('y');
zlabel('z');
grid on

例4:绘制上半圆锥面截单位球面所得到曲面的散点图。
参考代码:(借用了球面坐标)
clear all
clc
r=1;
for phi = 0:pi/80:pi/4
for theta = 0:pi/20:2*pi
x = r*sin(phi)*cos(theta);
y = r*sin(phi)*sin(theta);
z = r*cos(phi);%球面上的竖坐标
zz = r*sin(phi);%圆锥面上的竖坐标
col1 = abs(x);
col2 = abs(y);
col3 = abs(z);
plot3(x,y,z,'.','color',[col1,col2,col3]);%球面
hold on
plot3(x,y,zz,'r.')%圆锥面
end
end
axis equal
xlabel('x');
ylabel('y');
zlabel('z');
运行结果:
边栏推荐
猜你喜欢

七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间

并查集详解

搭建好pytorch环境后,pip和conda指令不能用

The problem of disorganized data output by mnn model

In V8 how arrays (with source code, picture and text easier to understand)

Nanoprobes Mono- Sulfo -NHS-Nanogold的使用和应用

带你造轮子,自定义一个随意拖拽可吸边的悬浮View组件

Apple told Qualcomm: I bought a new campus for $445 million and may plan to speed up self-development of baseband chips

伦敦银最新均线分析系统怎么操作?

R3LIVE论文学习(二):VIO子系统
随机推荐
XSLT – 服务器端概述
Salesforce's China business may see new changes, rumors may be closing
JS get parameter value of URL hyperlink
2022-08-03:以下go语言代码输出什么?A:2;B:3;C:1;D:0。 package main import “fmt“ func main() { slice := []i
一文搞定 SQL Server 执行计划
孙宇晨受邀参加36氪元宇宙峰会并发表主题演讲
Talking about the future development direction of my country's industrial parks
Shell编程之循环语句(for、while)
状态机实验
Nanoprobes 棕榈酰纳米金相关说明书
rsync basic usage
internship:编写excel表的上传方法(导入)
Using matlab to solve the linear optimization problem based on matlab dynamic model of learning notes _11 】 【
Why Flutter Flutter of tutorials is the best choice for business?
微服务的简单介绍
2022-08-03: What does the following go code output?A: 2; B: 3; C: 1; D: 0.package main import "fmt" func main() { slice := []i
【性能优化】MySQL性能优化之存储引擎调优
带你造轮子,自定义一个随意拖拽可吸边的悬浮View组件
Node.js的基本使用(三)数据库与身份认证
Prometheus监控Harbor(二进制版)