Using 'tiledlayout', is it possible to incorporate a zoomed-in section of the main plot within the main plot itself for each tile?

19 ビュー (過去 30 日間)
Hi, I created 3 main plots (black square) using 'tiledlayout', and i would like to include a zoomed-in area of each main plots (red square) within the same tile. Is this possible to do? The figure below shows, what i would like.

採用された回答

Image Analyst
Image Analyst 2024 年 5 月 15 日
You can call axes() and position it and then draw stuff in it. See my attached inset demos.

その他の回答 (1 件)

Rishi
Rishi 2024 年 5 月 15 日
Hi S C,
I understand that you want to zoom in a subsection of a plot in a 'tiledlayout', and plot that subsection on top of the main plot.
A similar question has been answered below, albeit not using 'tiledplot':
To achieve the same result when 'tiledlayout' is used, you can create an overlay axes for the zoomed in subplot and manually position the subplot over the primary axis. The below modified code showcases the same, where the primary axis is created within a 'tiledlayout'
clf();
% Create a tiled layout
t = tiledlayout(1,1);
% Create the primary axis in the tile
axPrimary = nexttile(1);
box(axPrimary, 'on');
axis(axPrimary, 'equal');
% Plot contour in the primary axis
Z = peaks;
[~, ch] = contourf(axPrimary, Z);
% Choose section to isolate
xSection = [10, 25];
ySection = [20, 35];
% Show the section in the main axis
rectangle(axPrimary,'Position',[xSection(1),ySection(1),range(xSection),range(ySection)], 'EdgeColor', 'r');
% After plotting the main figure, create an overlay axes for the zoomed-in subplot
% This axes is manually positioned over the primary axes
axSecondary = axes('Position',[0.5 0.5 0.4 0.4], 'Box', 'on');
axis(axSecondary, 'equal');
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));
You can also go through the following links to have a look at other solutions as well:
Hope this helps!

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by