How to zoom in the portion of the same contour as shown in figure

조회 수: 13 (최근 30일)
shadman khan
shadman khan 2020년 1월 21일
편집: Adam Danz 2020년 1월 24일
i have made this contour using MATLAB.
THE Zoom in plot shown is created by using the figure tools manually
How can i do this using the Contourf command for the 25<Xcordinates<50 and 25<Ycordinates<50
i need to create 60 plots like this and zooming in isn't possible to perform manually
The main problem is how to plot a contour on top of another contour?

채택된 답변

Adam Danz
Adam Danz 2020년 1월 21일
편집: Adam Danz 2020년 1월 24일
The content of the subplot merely shows a subsection of the data; it is not 'zoomed' or rescaled.
You'll have to build this manually by following just a few steps.
1) Create a secondary axes within the primary axes.
clf()
axPrimary = axes('Units','Normalize','Box','on');
axSecondary = axes('Units','Normalize','Box','on');
scale = 0.45; % percentage of original size
axSecondary.Position(3:4) = scale * axSecondary.Position(3:4);
axSecondary.Position(1:2) = axPrimary.Position(1:2) + axPrimary.Position(3:4)*(1-scale);
2) Plot the contour as you normally would and specify the primary axis handle as the parent. Then plot the contour subsection by specifying which coordinates to plot and specify the secondary axis handle as the parent.
% Plot contour (it doesn't matter which syntax you use)
Z = peaks;
[~, ch] = contourf(axPrimary, Z);
% Choose section to isolate
xSection = [10, 25]; % x-bounds
ySection = [20, 35]; % y-bounds
% Get index values of section
xIdx = ch.XData >= xSection(1) & ch.XData <= xSection(2);
yIdx = ch.YData >= ySection(1) & ch.YData <= ySection(2);
% Plot section in secondary axis
[~,ch2] = contourf(axSecondary, ch.XData(xIdx), ch.YData(yIdx), ch.ZData(yIdx,xIdx))
ch2.LevelList = ch.LevelList;
caxis(axSecondary, caxis(axPrimary))
axis(axPrimary,'equal')
axis(axSecondary,'equal')
% Show the section in the main axis, if you want to.
rectangle(axPrimary,'Position',[xSection(1),ySection(1),range(xSection),range(ySection)])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by