matlabaxis(周一分享十一Matlab二维绘图2)

管理员 2024-09-20 21:43:26 0

Matlab二维绘图2

Matlab 2D plot2

周一分享(十一):Matlab二维绘图2

分享兴趣,传播快乐,增长见闻,留下美好。

亲爱的您,

这里是LearingYard学苑!

今天小编为大家带来Matlab二维绘图。

欢迎您的用心访问!

本期推文阅读时长大约5分钟,请您耐心阅读。

Share interest, spread happiness,increase knowledge, and leave beautiful.

Dear you,

this is the LearingYard Academy!

Today, the editor brings two-dimensional drawing in Matlab.

Welcome your visit!

The reading time of this tweet is about 5 minutes, please read it with patience.

一、二维绘图基本语法

2D Drawing Basic Syntax

1、bar——条形图

bar - bar chart

bar(y)创建一个条形图,y中的每个元素对应一个条形。如果y是 m×n矩阵,则bar创建每组包含n个条形的m个组。bar(x,y)在x指定的位置绘制条形。bar(___,width)设置条形的相对宽度以控制组中各个条形的间隔。将width指定为标量值。可以将此选项与前面语法中的任何输入参数组合一起使用。bar(___,style)指定条形组的样式。例如,使用 'stacked' 将每个组显示为一个多种颜色的条形。bar(___,color)设置所有条形的颜色。bar(___,Name,Value)使用一个或多个名称值对组参数指定条形图的属性。仅使用默认'grouped'或'stacked'样式的条形图支持设置条形属性。在所有其他输入参数之后指定名称值对组参数。bar(y) creates a bar chart, one bar for each element in y. If y is an m-by-n matrix, then bar creates m groups of n bars each.bar(x,y) draws a bar at the position specified by x.bar(___,width) sets the relative width of the bars to control the spacing of the bars in the group. Specify width as a scalar value. You can use this option with any combination of input parameters in the preceding syntax.bar(___,style) specifies the style of the bar group. For example, use 'stacked' to display each group as a multi-colored bar.bar(___,color) sets the color of all bars.bar(___,Name,Value) specifies the properties of the bar using one or more name-value pair arguments. Setting bar properties is only supported for bar charts using the default 'grouped' or 'stacked' style. Specify name-value pair arguments after all other input arguments.

2、pie——饼图

pie - pie chart

pie(X)使用X中的数据绘制饼图。饼图的每个扇区代表X中的一个元素。pie(X,explode)将扇区从饼图偏移一定位置。explode是一个由与X对应的零值和非零值组成的向量或矩阵。pie函数仅将对应于explode中的非零元素的扇区偏移一定的位置。pie(X,labels)指定用于标注饼图扇区的选项。pie(X,explode,labels)偏移扇区并指定文本标签。pie(X) draws a pie chart using the data in X. Each sector of the pie chart represents an element in X.pie(X,explode) offsets the slice from the pie by a certain position. explode is a vector or matrix of zero and non-zero values corresponding to X. The pie function only offsets the sectors corresponding to non-zero elements in explode by a certain position.pie(X, labels) specifies options for labeling pie slices.pie(X,explode,labels) Offset sectors and specify text labels.

3、plotyy——创建具有两个Y轴的图形

plotyy - create a graph with two Y axes

plotyy(X1,Y1,X2,Y2)绘制Y1对X1的图,在左侧显示y轴标签,并同时绘制Y2对 X2的图,在右侧显示y轴标签。plotyy(X1,Y1,X2,Y2,function)使用指定的绘图函数生成图形。[AX,H1,H2] = plotyy(___)返回AX中创建的两个坐标区的句柄,以及H1和H2中每个绘图的图形对象的句柄。AX(1)是左边的坐标区,AX(2)是右边的坐标区。plotyy(X1,Y1,X2,Y2) plots Y1 against X1 with the y-axis labels on the left, and also plots Y2 against X2 with the y-axis labels on the right.plotyy(X1,Y1,X2,Y2,function) generates a graph using the specified plotting function.[AX,H1,H2] = plotyy(___) returns handles to the two axes created in AX, and a handle to the graphics object for each plot in H1 and H2. AX(1) is the left axes and AX(2) is the right axes.

4、polarplot——极坐标中绘制线条

polarplot - draw lines in polar coordinates

polarplot(theta,rho)在极坐标中绘制线条,由theta表示弧度角,rho表示每个点的半径值。输入必须是长度相等的向量或大小相等的矩阵。如果输入为矩阵,polarplot 将绘制 rho 的列对theta的列的图。也可以一个输入为向量,另一个为矩阵,但向量的长度必须与矩阵的一个维度相等。polarplot(theta,rho,LineSpec)设置线条的线型、标记符号和颜色。polarplot(theta1,rho1,...,thetaN,rhoN)绘制多个rho,theta对组。polarplot(theta1,rho1,LineSpec1,...,thetaN,rhoN,LineSpecN)指定每个线条的线型、标记符号和颜色。polarplot(rho) 按等间距角度(介于0和2π之间)绘制rho中的半径值。polarplot(rho,LineSpec)设置线条的线型、标记符号和颜色。polarplot(theta,rho) draws lines in polar coordinates, where theta represents the angle in radians and rho represents the radius value of each point. Inputs must be vectors of equal length or matrices of equal size. If the input is a matrix, polarplot will plot the columns of rho against the columns of theta. It is also possible to have one input as a vector and the other as a matrix, but the length of the vector must be equal to one dimension of the matrix.polarplot(theta, rho, LineSpec) sets the line style, marker symbols, and color of the lines.polarplot(theta1,rho1,...,thetaN,rhoN) plots multiple rho,theta pairs.polarplot(theta1,rho1,LineSpec1,...,thetaN,rhoN,LineSpecN) specifies the linetype, marker symbol, and color for each line.polarplot(rho) plots the radius values in rho by equally spaced angles (between 0 and 2π).polarplot(rho, LineSpec) sets the line style, marker symbols, and color of the lines.

二、示例

Example

1、绘制一个条形图

Draw bar chart

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

2、堆叠条形图

Stacked Bar Chart

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

3、绘制一个饼图

Draw a pie chart

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

4、使用两个y轴在一个图上绘制两个数据集,添加标题和轴标签

Plot two datasets on one graph with two y-axes, add titles and axis labels

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

5、绘制极坐标图

Plot polar coordinates

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

6、在极坐标中绘制两个线条

Draw two lines in polar coordinates

代码如下图所示:

The code is shown below:

周一分享(十一):Matlab二维绘图2

运行结果如下图所示:

The running result is shown in the following figure:

周一分享(十一):Matlab二维绘图2

今天的分享就到这里了。

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

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's it for today's sharing.

If you have a unique idea about today’s article,

welcome to leave us a message,

let us meet tomorrow.

I wish you a happy day today!

参考资料:谷歌翻译、百度、哔哩哔哩

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

文字|Zheng

排版|Zheng

审核|任务达人

相关文章