颜读(18):Matlab学习之二维图—plot函数绘图
分享兴趣,传播快乐,
增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。
今天小编为大家带来
“颜读(18):Matlab学习之二维图—plot函数绘图”
欢迎您的访问!
Share interest, spread happiness,
increase knowledge, and leave beautiful.
Dear, this is the LearingYard Academy!
Today, the editor brings the
"Yan Du (18):Learning MATLAB: 2D Plotting with the plot Function"
Welcome to visit!
一、思维导图(Mind Mapping)
二、二维图的绘制步骤(Steps for drawing a two-dimensional (2D) diagram)
(1)选择plot函数(Select the plot function)
在Matlab中,plot函数是最常用的绘图函数之一,主要用于创建二维线图。它能够将数据点连接成线,直观地展示数据趋势。plot(x,y)用来创建y中数据对x中对应值的二维线图。
In MATLAB, the plot function is one of the most commonly used functions for drawing graphs, primarily used to create two-dimensional line plots. It connects data points into lines to visually represent data trends. The plot(x, y) function is used to create a two-dimensional line plot of the data in y against the corresponding values in x.
(2)添加线条颜色、线形和标记(Add line color, line style, and markers)
在Matlab的图像中添加线条颜色、线形和标记,可以使用预设的颜色、线形和标记代码。这里小编将y1设置成蓝色、菱形、画点线,y2设置成绿色、五角星形、点线,y3设置成红色、圆形、实线。
To add line color, line style, and markers in MATLAB plots, you can use predefined codes for colors, line styles, and markers. Here, I'll sety1 to be blue with diamond-shaped markers and a dotted line, y2 to be green with star-shaped markers and a dotted line, and y3 to be red with circular markers and a solid line.
(3)添加文本注释(Add text annotations)
在Matlab中,text和gtext函数用于在图形上添加文本标注,两者的主要区别是:text函数可以在图形的指定坐标位置添加文本,并支持格式化和样式自定义。gtext 函数会让鼠标指针变成十字形,点击图形上的任意位置即可放置文本,适合需要手动定位的场景。gtext函数添加文本标注具体操作如下。
In MATLAB, the text and gtext functions are used to add text annotations to graphics. The main difference between them is that the text function allows you to add text at specified coordinate positions on the graph and supports formatting and style customization. The gtext function turns the mouse pointer into a crosshair, enabling you to place text anywhere on the graph by clicking, making it suitable for scenarios where manual positioning is required. The specific steps for adding text annotations using the gtext function are as follows.
(4)添加图例(Add a legend)
在Matlab中,legend函数用于为图形添加图例,标识以区分多条曲线或数据系列,让读者能快速理解不同线条/标记的含义,legend函数的核心是将图例标签与绘制图形中的对象(如曲线)按顺序关联。
In MATLAB, the legend function is used to add a legend to a graph, which helps identify and distinguish multiple curves or data series. This enables readers to quickly understand the meanings of different lines or markers. The core of the legend function is to associate legend labels with the objects (such as curves) in the plotted graph in sequence.
(5)添加标题以及坐标轴的描述(Add titles and descriptions for the axes)
在Matlab中,为图形添加标题和坐标轴描述可以让图表更清晰易懂。常用的函数包括:title(添加图形标题)、xlabel(添加x轴描述)、ylabel(添加y轴描述)、zlabel(3D图形中添加z轴描述)。这里我根据上方绘制的图像添加x轴描述和图形标题。
In MATLAB, adding titles and descriptions for the axes can make the chart clearer and easier to understand. Commonly used functions include:title (to add a title to the graph), xlabel (to add a description for the x-axis), ylabel (to add a description for the y-axis), and zlabel (to add a description for the z-axis in 3D graphs). Here, I will add an x-axis description and a graph title based on the previously plotted image.
学会了的话,不妨就动手试试。
If you've learned it, why not give it a try yourself?
今天的分享就到这里了,
如果您对文章有独特的想法,
欢迎给我们留言,
让我们相约明天。
祝您今天过得开心快乐!
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!
翻译:文心一言
参考资料:CSDN博客、ChatGpt、MATLAB官网
本文由LearningYard学苑整理发出,如有侵权请在后台留言!