玖叶教程网

前端编程开发入门

小杨研学(18)-学习Matlab画图之基础三维图绘制

分享兴趣,传播快乐,

增长见闻,留下美好。

亲爱的您,这里是LearningYard学苑!

今天小编为大家带来Matlab绘制图的介绍第三期。

欢迎您的访问!

本期阅读时长大约为6分钟,请您耐心阅读。

Share interest, spread happiness,

increase knowledge, and leave beautiful.

Dear, this is the LearingYard Academy!

Today, the editor brings the “introduction of

Matlab plotting” Part Ⅲ.

Welcome to visit!

This tweet usually takes about 6 minutes to read,

please be patient and read.

思维导图 Mind mapping

精读内容 Intensive reading

1. 三维曲线图 Plot3d

plot3( )的含义就是绘制三维空间中的坐标,它与plot的区别就是多出了z轴需要定义,要在同一组坐标轴上绘制多组坐标,请将 X、Y 或 Z 中的至少一个指定为矩阵,其他指定为向量。例如:

The meaning of plot3( ) is to plot the coordinates in three-dimensional space, the difference between it and plot is that more z-axis needs to be defined, to plot multiple sets of coordinates on the same set of axes, please specify at least one of X, Y, or Z as a matrix, and the others as vectors. For example:

x=0:0.1:3*pi;

z1=sin(x);z2=sin(2*x);z3=sin(3*x);

y1=zeros(size(x));y2=ones(size(x));y3=y2./2;

plot3(x,y1,z1,'r',x,y2,z2,'g',x,y3,z3,'b');

grid on;

xlabel('x');ylabel('y');zlabel('z');

2. 网格曲面图 Mesh

网格曲面图的代码为mesh(),mesh(X,Y,Z) 创建一个网格图,该网格图为三维曲面,有实色边颜色,无面颜色。该函数将矩阵 Z 中的值绘制为由 X 和 Y 定义的 x-y 平面中的网格上方的高度。边颜色因 Z 指定的高度而异。具体代码如下:

The code for the mesh surface map is mesh(), mesh(X,Y,Z) creates a mesh plot, which is a three-dimensional surface that has solid edge colors and no face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y. The edge colors vary according to the heights specified by Z. The code is as follow:

x = -2:0.25:2;

y = -2:0.25:2;

[X,Y] = meshgrid(x);

F = X.*exp(-X.^2-Y.^2);

mesh(X,Y,F);

colorbar;

title('网格曲面图')

3. 曲面图 Surf

曲面图(Surface)的代码为surf(),surf(X,Y,Z) 创建一个三维曲面图,它是一个具有实色边和实色面的三维曲面。该函数将矩阵 Z 中的值绘制为由 X 和 Y 定义的 x-y 平面中的网格上方的高度。曲面的颜色根据 Z 指定的高度而变化。具体代码如下:

The code for Surface is surf(), surf(X,Y,Z) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y. The color of the surface varies according to the heights specified by Z. The code is as follow:

x = -2:0.25:2;

y = -2:0.25:2;

[X,Y] = meshgrid(x);

F = X.*exp(-X.^2-Y.^2);

surf(X,Y,F);

shading flat;

colorbar;

title('曲面图')

4. 球面图 Sphere

[X,Y,Z] = sphere 返回球面的 x、y 和 z 坐标而不对其绘图。返回的球面的半径等于 1,由 20×20 个面组成。该函数以三个 21×21 矩阵形式返回 x、y 和 z 坐标。具体代码如下:

[X,Y,Z] = sphere returns the x, y, and z coordinates of a sphere without drawing it. The returned sphere has a radius equal to 1 and consists of 20-by-20 faces. The code is as follow:

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);

colorbar;

colormap("jet")

其中sphere代表创建球面;shading flat代表隐藏网格线的颜色;light代表不同位置的打光角度;material代表赋予球面更多金属质感;view代表视角;axis vis3d off代表关闭坐标区背景的显示;colormap()代表不同预定义的颜色图。

Sphere stands for creating a sphere, shading flat for hiding the color of the gridlines, light for the lighting angle at different positions, material for giving the sphere a more metallic feel, view for the viewing angle, axis vis3d off for turning off the display of the background in the coordinate area, and colormap() for different predefined color maps. .

知识补充 Knowledge supplement

二维和三维网格 Meshgrid

meshgrid是Matlab中用于生成网格采样点的函数,向量转化为矩阵。[X,Y]=meshgrid指令的作用是基于向量 x 和 y 中包含的坐标返回二维网格坐标。X 是一个矩阵,每一行是 x 的一个副本;Y 也是一个矩阵,每一列是 y 的一个副本。坐标 X 和 Y 表示的网格有 length(y) 个行和 length(x) 个列。

meshgrid is a function used in Matlab to generate mesh sample points, vectors are transformed into matrices.[X,Y] = meshgrid(x,y) returns 2-D grid coordinates based on the coordinates contained in vectors x and y. X is a matrix where each row is a copy of x, and Y is a matrix where each column is a copy of y. The grid represented by the coordinates X and Y has length(y) rows and length(x) columns.

颜色图 Colormap

颜色图是由值组成的矩阵,这些值用于定义诸如曲面、图像以及补片之类的图形对象的颜色。MATLAB 通过将数据值映射到颜色图中的颜色来绘制这些对象Matlab中预设了数十种不同的colormap颜色图,如图:

A colormap is a matrix of values that define the colors for graphics objects such as surface, image, and patch objects. MATLAB draws the objects by mapping data values to colors in the colormap. Dozens of different colormap color maps are preset in Matlab, as shown in Fig:

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's all for today's sharing.

If you have a unique idea about the article,

please leave us a message,

and let us meet tomorrow.

I wish you a nice day!

参考资料:Bilibili、Matlab帮助中心、DeepL翻译

本文由LearningYard学苑原创,如有侵权请在后台留言!

LearningYard学苑

文字|Young

排版|Young

审核|Zheng

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言