How do I create a plot within another plot?
조회 수: 20 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2010년 8월 25일
댓글: Walter Roberson
2022년 9월 6일
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
2017년 6월 30일
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
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 Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!