北屋教程网

专注编程知识分享,从入门到精通的编程学习平台

晴读(19):MATLAB二维图制作指南_matlab画二维图代码

分享兴趣,传播快乐,

增长见闻,留下美好。

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

今天小编为您带来“晴读(19):MATLAB二维图制作指南”。

欢迎您的访问!

Share interest, spread happiness,

increase knowledge, and leave beautiful.

Dear, this is the LearingYard Academy!

Today, the editor brings the

"Qing Reading (19):MATLAB 2D Plotting Guide".

Welcome to visit!


一、思维导图(Mind Map)

二、二维图简介(Introduction to 2D Plots)

在论文中,二维图是高效传递数据信息与研究结论的重要工具。它能够将复杂的数据关系(如变量间的变化趋势、不同实验组的结果差异等)进行直观可视化呈现,借助`plot`绘制的曲线,结合`xlabel`、`ylabel`清晰标注坐标轴含义,`legend`区分不同数据系列,能让读者快速理解数据规律(如随时间的变化、不同参数下的结果对比);通过设置多样线型、标记与颜色,可在同一图中清晰展现多组数据差异,辅助作者简洁、有力地论证研究观点,提升论文逻辑的直观性与结论的可信度,帮助读者跨越纯文字与数字的理解门槛,高效抓取关键信息。

In academic papers, 2D graphs are important tools for efficiently conveying data information and research conclusions. They can intuitively visualize complex data relationships (such as the changing trends between variables, differences in results among different experimental groups, etc.). With curves plotted using `plot`, combined with `xlabel` and `ylabel` to clearly label the meanings of the axes, and `legend` to distinguish different data series, readers can quickly understand data patterns (such as changes over time, comparisons of results under different parameters). By setting various line styles, markers, and colors, differences among multiple sets of data can be clearly displayed in the same graph, helping authors concisely and powerfully demonstrate their research viewpoints, enhancing the intuitiveness of the paper's logic and the credibility of its conclusions, and assisting readers in overcoming the barrier of understanding pure text and numbers to efficiently grasp key information.

三、具体指令(Specific Instructions)

1.基础准备:创建数据(以正弦、余弦曲线为例),首先需要定义x 轴数据,再据此生成对应的y 数据,以此作为绘图的“原材料”。

1. Basic preparation: Create data (taking sine and cosine curves as examples). First, it is necessary to define the x-axis data, and then generate the corresponding y-axis data based on it, which serves as the "raw material" for plotting.

2.基础绘图:plot函数用于绘制二维曲线,支持自定义线型(如-表示实线、--表示虚线)、标记(如o表示圆圈、x表示叉号)、颜色(如r表示红色、g表示绿色),其语法为plot(x, y, '线型+标记+颜色')。使用时,若需在同一图中绘制多条曲线,需加上hold on;以保持画布,否则新绘制的曲线会覆盖原有曲线;还可通过可选参数LineWidth设置线条粗细,增强可视化效果。

2. Basic plotting: The `plot` function is used to draw 2D curves and supports custom line styles (e.g., '-' for solid lines, '--' for dashed lines), markers (e.g., 'o' for circles, 'x' for crosses), and colors (e.g., 'r' for red, 'g' for green). Its syntax is `plot(x, y, 'line style + marker + color')`. When using it, if you need to draw multiple curves in the same figure, you must add `hold on;` to keep the canvas, otherwise the newly drawn curve will overwrite the existing one. You can also set the line thickness through the optional parameter `LineWidth` to enhance the visualization effect.

3.坐标轴标注:xlabel/ylabel。其作用是用来给x 轴、y 轴添加描述文本。语法:xlabel('x 轴描述');ylabel('y 轴描述')。

3. Axis labeling: `xlabel`/`ylabel`. Their function is to add descriptive text to the x-axis and y-axis. Syntax: `xlabel('x-axis description')`; `ylabel('y-axis description')`.

4.图标题:title,其作用是可以给整个图加标题,增强可读性。语法:title('标题文本')。

4. Figure title: `title`, whose function is to add a title to the entire figure to enhance readability. Syntax: `title('title text')`.

5.图例说明:legend的作用则是给多条曲线加“图例标签”,区分不同数据含义。语法:legend('曲线1名称', '曲线2名称')。

5. Legend explanation: The function of `legend` is to add "legend labels" to multiple curves to distinguish the meanings of different data. Syntax: `legend('Name of Curve 1', 'Name of Curve 2')`.

6.文本标注的函数指令:text/gtext。其作用是用来在图中指定坐标(text)或手动点击位置(gtext)添加文本说明。text(指定坐标),语法:text(x坐标, y坐标, '文本内容', '属性'),gtext(手动交互),语法:gtext('文本内容')。

6. Function commands for text annotation: `text`/`gtext`. Their function is to add text descriptions at specified coordinates in the figure (`text`) or at manually clicked positions (`gtext`). For `text` (specifying coordinates), the syntax is: `text(x-coordinate, y-coordinate, 'text content', 'property')`; for `gtext` (manual interaction), the syntax is: `gtext('text content')`.

7.使用RGB自定义颜色绘制辅助线时,首先确定辅助线的横轴数据为x,纵轴数据为0.5倍的sin(x)加0.5即0.5*sin(x)+0.5,设点线(':')、RGB黄色[1 1 0](参数'Color')、线宽2(参数'LineWidth'),用plot函数绘图,最后以hold off结束保持模式。

7. When drawing auxiliary lines with custom RGB colors, first determine that the x-axis data of the auxiliary line is x, and the y-axis data is 0.5 times sin(x) plus 0.5, i.e., 0.5*sin(x)+0.5. Set the dotted line (':'), RGB yellow [1 1 0] (parameter 'Color'), and line width 2 (parameter 'LineWidth'), use the plot function to draw, and finally end the hold mode with hold off.

8.坐标轴范围与属性:axes/xlim/ylim(可选优化)。其中axes 的作用是用来创建或设置坐标轴对象,可统一控制字体、背景等(进阶用法,示例简化演示)。而xlim和ylim 的作用是可以手动设置x 轴、y 轴显示范围。需要注意的是,创建新坐标轴,会覆盖当前图中的旧坐标轴,导致原有图形被隐藏。

8. Axis range and properties: `axes`/`xlim`/`ylim` (optional optimization). The function of `axes` is to create or set axis objects, which can uniformly control fonts, backgrounds, etc. (advanced usage, simplified demonstration in examples). The functions of `xlim` and `ylim` are to manually set the display ranges of the x-axis and y-axis. It should be noted that creating a new axis will overwrite the old axis in the current figure, causing the original graph to be hidden.

四、注意事项(Notes for Attention)

1.用plot绘图后若要继续添加内容,需先加'hold on',否则新绘图会覆盖原有图形;完成后可用'hold off'结束保持状态。

1. After plotting with `plot`, if you need to continue adding content, you must first add `hold on`; otherwise, the new plot will overwrite the existing one. Once finished, you can use `hold off` to end the hold state.

2.调整坐标轴属性时,用'gca'获取当前坐标轴后再用'set'修改(如'set(gca, 'FontSize', 12)'),避免直接用'axes()'新建坐标轴,否则会覆盖已画好的图形。

2. When adjusting axis properties, use `gca` to get the current axis first and then modify it with `set` (e.g., `set(gca, 'FontSize', 12)`). Avoid directly creating a new axis with `axes()`, as it will overwrite the already drawn graph.


今天的分享就到这里了。

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

欢迎给我们留言,让我们相约明天。

祝您今天过得开心快乐!

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!

文案hu

排版hu

审核yyz

翻译:谷歌翻译

参考资料:百度百科,ChatGPT,bilibili

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

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