Using 'tiledlayout', is it possible to incorporate a zoomed-in section of the main plot within the main plot itself for each tile?
24 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Image Analyst
on 15 May 2024
You can call axes() and position it and then draw stuff in it. See my attached inset demos.
More Answers (1)
Rishi
on 15 May 2024
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!
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!