摘要:Here, the editor has plotted three intersecting lines in Figure 1, customizing each with distinct line styles, marker types, and c
分享兴趣,传播快乐,
增长见闻,留下美好!
亲爱的您,这里是LearningYard学苑。
今天小编为大家带来
“颜读(21):Matlab学习之绘制图中图和axes函数”
欢迎您的访问!
Share interest, spread happiness,
increase knowledge, and leave beautiful.
Dear, this is the LearingYard Academy!
Today, the editor brings the
"Yan Du (21): Matlab Learning: Creating Inset Plots and Using the axes Function"
Welcome to visit!
一、思维导图(Mind Mapping)
二、绘制图中图(Inset Plot)
这里小编在figure1中绘制三条交叉的线条,并给这三条线设置好线条不同的线形、标记类型、颜色,具体代码和运行结果如下图所示。
Here, the editor has plotted three intersecting lines in Figure 1, customizing each with distinct line styles, marker types, and colors. The specific code and resulting visualization are shown below.
接下来选择原图,利用快捷键“CTRL+C”和快捷键“CTRL+V”即可复制和粘贴原图,然后自己手动调整子图大小,随意选择一处线条交汇处并放大该交汇处。之后在原图上方点击“数据提示”,用鼠标选中交叉处进行标记,最终图形结果如下图所示。
Next, select the original figure, then use the keyboard shortcuts "CTRL+C"
and "CTRL+V" to copy and paste it. Manually adjust the size of the inset subplot, choose any intersection point of the lines, and zoom in on that area. Afterward, click "Data Tips" above the original figure and use the mouse to select the intersection point for marking. The final graphical result is shown below.
三、axes函数绘制图中图(Using the axes function to create an inset plot)
在MATLAB中,axes 函数用于创建或切换坐标轴,它是绘制"图中图"(即在主图中嵌入子图)的核心工具。与 subplot 不同,axes 允许自由定位子图(甚至重叠),适合复杂布局。axes 适合需要精确定位或重叠子图的场景(如局部放大、数据对比)。其关键参数“Position”定义子图位置/大小,“hold on”保持主图不被覆盖。
In MATLAB, the axes function is used to create or switch coordinate axes, serving as the core tool for drawing "inset plots" (i.e., embedding subplots within a main figure). Unlike subplot, axes allows flexible positioning of subplots (even overlapping ones), making it ideal for complex layouts. It is particularly suited for scenarios requiring precise positioning or overlapping subplots, such as zoomed-in views or data comparisons. Key parameters like 'Position' define the subplot's location and size, while 'hold on' prevents the main plot from being overwritten.
首先小编还是以上方的原图为例,然后使用axes函数创建子图,并指定其位置(Position参数),再手动调整子图合适大小。
First, let's take the original figure above as an example. Then, we'll use the axes function to create a subplot, specify its position using the 'Position' parameter, and manually adjust the subplot to an appropriate size.
axes(‘position’,[0.4 0.7 0.5 0.7]); 代表小图的位置,matlab中以figure区域左下坐标为(0,0),右上为(1,1)。所以该段代码中的小图左下角对应距整体长度0.4处(从左起),整体高度的0.7处(从下起,且可以认为是坐标值),而子图的宽度为原有的0.5,高度为原有的0.7。
The code axes ('position', [0.4 0.7 0.5 0.7]) defines the position of the inset subplot. In MATLAB, the coordinate system of the figure region uses (0, 0) as the bottom-left corner and (1, 1) as the top-right corner. Therefore, in this code, the bottom-left corner of the inset is located at 0.4 of the total width (from the left edge) and 0.7 of the total height (from the bottom edge, treated as a coordinate value). The subplot has a width of 0.5 and a height of 0.7 relative to the figure's dimensions.
最后我们可以调整子图样式,这里小编设置了子图标题,交汇处的数据提示,运行结果如下图所示。
Finally, we can customize the subplot's appearance. Here, the editor has added a subplot title and enabled data tips at the intersection point. The resulting visualization is shown below.
学会了的话,不妨就动手试试。
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博客、deepseek、MATLAB官网
本文由LearningYard学苑整理发出,如有侵权请在后台留言!
来源:LearningYard学苑