How do I create a plot within another plot?

19 次查看(过去 30 天)
I would like to generate a second set of axes within a plot to display a detailed view of a part of the original figure.

采纳的回答

MathWorks Support Team
The ability to use a detailed blown-up figure within a main figure window is not automatically available in MATLAB. To work around this issue, execute the script demonstrated in the following example.
1. Create data and plot the primary figure.
x = -pi:0.01:pi;
y = 2*sin(12*x) + 3*cos(0.2*pi+2);
plot(x,y, 'k');
2. Find the position of the current axes and then create a small axes using that position data.
p = get(gca, 'Position');
h = axes('Parent', gcf, 'Position', [p(1)+.06 p(2)+.06 p(3)-.5 p(4)-.5]);
3. You can now plot data on the second axes and zoom in on specific points.
plot(h, x, y, 'r');
set(h, 'Xlim', [-0.2 0], 'Ylim', [-5 -4]);
4. You can also turn off the tick marks on your small axes.
set(h, 'XTick', [], 'YTick', []);
After the axes are positioned as desired, You can add a rectangle and text arrow to visually link the data on the small axes with the data on your origional axes. From the figure window drop-down menu, you may select “insert->rectangle” and “insert->arrow”.
  1 个评论
Walter Roberson
Walter Roberson 2022-9-6
You can use the above techniques to insert a second axes with the same position as the current axes. You might need extra work with linkaxes() to have the extra axes automatically reposition when the tile repositions as more tiles are added.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

产品


版本

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by