天天看点

越览(14)——Matlab学习笔记(1):绘制二维图

作者:LearningYard学苑
越览(14)——Matlab学习笔记(1):绘制二维图

分享兴趣,传播快乐,

增长见闻,留下美好。

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

今天小编为大家带来文章“越览(14)——Matlab学习笔记(1):绘制二维图。”

欢迎您的访问。

Share interest, spread happiness,

increase knowledge,and leave beautiful.

Dear, this is LearningYard Academy!

Today, the editor brings you the article “Yue Lan (14):

Matlab Study Notes (1): Drawing 2D Diagrams.”

Welcome to visit!

一、思维导图(Mind Maps)

越览(14)——Matlab学习笔记(1):绘制二维图

二、数据图像绘制简介(Introduction to Data Image Rendering)

数据可视化的目的在于,通过图形从将一堆杂乱的离散数据中观察数据间的内在关系,感受由土星所传递的内在的本质。Matlab特别注重数据的图形表示,并不断地采用新技术改进,并完备其可视化功能。

The purpose of data lake visualization is to observe the internal relationship between data through graphs from a bunch of messy discrete data, and feel the inherent essence conveyed by Saturn. Matlab pays special attention to the graphical representation of data, and constantly adopts new technologies to improve and complete its visualization functions.

三、二维图的绘制方法(Drawing method of two-dimensional graph)

(一)基本语法(Basic grammar)

Plot函数是用于绘制二维图形的核心工具,它可以帮助用户直观展示数据点之间的关系,或者描绘数学函数的变化趋势。

The Plot function is a core tool for drawing two-dimensional graphs, which can help users visualize the relationship between data points or depict the changing trend of mathematical functions.

plot(X,Y)可以用来创建 Y 中数据对 X 中对应值的二维线图。

Plot (X, Y) can be used to create a two-dimensional line plot of the data in Y against the corresponding values in X.

plot(X1,Y1,...,Xn,Yn) 可在同一组坐标轴上绘制多对 x 和 y 坐标。此语法可替代将坐标指定为矩阵的形式。

Plot (X1, Y1,..., Xn, Yn) plots multiple pairs of x and y coordinates on the same set of axes. This syntax is an alternative to specifying the coordinates as a matrix.

使用plot函数绘图时,先要取得x、 y坐标,然后再绘制曲线,x往往采取等间隔采样。在实际应用中,函数随着自变量的变化趋势未知,或者在不同区间函数频率特性差别大,此时使用plot函数绘制图形,如果自变量的采样间隔设置不合理,则无法反映函数的变化趋势。

When using the plot function to plot, first obtain the x and y coordinates, and then draw the curve. X is often sampled at equal intervals. In practical applications, the trend of the function with the independent variable is unknown, or the frequency characteristics of the function vary greatly in different intervals. At this time, the plot function is used to plot graphs. If the sampling interval of the independent variable is set irrationally, the change trend of the function cannot be reflected.

(二)实例操作(Instance operation)

在MATLAB中绘制二维图是一项基本且常用的功能,可以通过多种内置函数实现。接下来为大家介绍具体的绘制方法。

Drawing two-dimensional diagrams in MATLAB is a basic and commonly used function, which can be realized through a variety of built-in functions. Next, I will introduce the specific drawing method for you.

1.创建图像(Create image)

首先,创建一个变量x,它是介于0-5之间(每隔0.1取一个点)。在同一坐标系中绘制关于变量x的三条线。

First, create a variable x that is between 0 and 5 (taking a point every 0.1). Draw three lines about the variable x in the same coordinate system.

代码如下:

Code show as below:

越览(14)——Matlab学习笔记(1):绘制二维图

运行结果如下:

The results are as follows:

越览(14)——Matlab学习笔记(1):绘制二维图

2.图像的修饰(Retouching of images)

在MATLAB中,修饰二维图像线条可以通过多种方式实现,包括但不限于改变线条颜色、线型、标记符号、以及添加图例、标题、轴标签等。以下是一些基本的步骤和示例代码,展示如何进行这些修饰:

In MATLAB, modifying the lines of a 2D image can be done in a number of ways, including but not limited to changing the line color, line shape, marking symbols, and adding legends, captions, axis labels, etc. Here are some basic steps and sample code to show how to make these modifications:

(1)线条颜色与线型(Line color and line shape)

可以使用颜色名称或RGB值来指定线条颜色,将y1设置成黑色,y2设置成红色,y3设置成蓝色,再修改一下线型或数据点型。组合方式为‘色彩+线型’或‘色彩+点型’。

You can use the color name or RGB value to specify the line color, set y1 to black, y2 to red, y3 to blue, and modify the line or data point type. The combination method is'color + line type 'or'color + point type'.

代码如下:

Code show as below:

越览(14)——Matlab学习笔记(1):绘制二维图

运行结果如下:

The results are as follows:

越览(14)——Matlab学习笔记(1):绘制二维图

(2)添加文本注释(Add text comments)

gtext和text都是用于在图形中添加文本注释的函数,但它们的工作方式略有不同。gtext函数允许用户通过鼠标交互来放置文本。text函数允许你以编程方式在图形中指定的坐标(x, y)处添加文本字符串。这里的x和y是数值,它们定义了文本在图中的位置。

Both gtext and text are functions for adding text annotations to a graph, but they work slightly differently. The gtext function allows users to place text via mouse interaction. The text function allows you to programmatically add a text string at the coordinates (x, y) specified in the graph. Here x and y are numeric values that define the position of the text in the graph.

越览(14)——Matlab学习笔记(1):绘制二维图

(3)添加轴标签(Add axis label)

在MATLAB中,’xlabel’,‘ylabel’,和 ‘zlabel’分别是用来给二维或三维图形的x轴、y轴、z轴添加标签的函数,用于标注坐标轴所代表的变量名称或其他说明信息。

In MATLAB, 'xlabel', 'ylabel', and'zlabel 'are functions used to label the x-axis, y-axis, and z-axis of a two-dimensional or three-dimensional graph, respectively, to label the variable names or other descriptive information represented by the coordinate axes.

给刚刚所绘制的图添加轴标签:

Add axis labels to the diagram just drawn:

越览(14)——Matlab学习笔记(1):绘制二维图

(4)添加图例(Add legend)

legend函数用于创建图表的图例,它可以帮助标注图表中不同线条或标记所代表的含义。

The legend function is used to create the legend of a chart, which can help to label the meanings of different lines or markers in the chart.

越览(14)——Matlab学习笔记(1):绘制二维图

学会了的话,不妨现在就动手试试吧。

If you've learned it, you might as well try it now.

今天的分享就到这里了。

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

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

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!

文案|yyz

排版|yyz

审核|hzy

翻译:ChatGPT

参考资料:哔哩哔哩、CSDN博客

本文由LearningYard学苑整理发出,如有侵权请在后台留言!

继续阅读