# How to zoom a figure and show the details?

25 Ansichten (letzte 30 Tage)
Mpho Lencwe am 21 Jul. 2024 um 17:31
Kommentiert: Benjamin Kraus am 22 Jul. 2024 um 19:40
Good day,
How can I zoom a figure to show the details and include the zoomed area of the figure within the original figure?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Walter Roberson am 21 Jul. 2024 um 18:35
Create a second axes. copyobj() the content of the first axes to the second axes. Turn zoom on for the second axes.
Note: it is more work if the zoomed in version has to react to changes in the original plot.
##### 2 KommentareKeine anzeigenKeine ausblenden
Mpho Lencwe am 22 Jul. 2024 um 8:08
Hello @Walter Roberson thank you very much for your quick respnse. Can you provide a step by step guide if you have an opened MATLAB Figure such as the Figure toolbar?
Walter Roberson am 22 Jul. 2024 um 17:12
Are you working with figure() objects, or are you working with uifigure() objects (such as App Designer) ?

Melden Sie sich an, um zu kommentieren.

Benjamin Kraus am 22 Jul. 2024 um 19:34
Bearbeitet: Benjamin Kraus am 22 Jul. 2024 um 19:36
One way to do this is using tiledlayout.
t = tiledlayout(20,20);
% Create one big axes that fills the entire layout.
axbig = nexttile(t, [20 20]);
% Add the image to the big axes.
image(axbig, im);
% Now add a small axes in the upper right corner of the big axes.
axsmall = copyobj(axbig, t);
n = tilenum(t, 2, 16);
axsmall.Layout.Tile = n;
axsmall.Layout.TileSpan = [4 4];
% Now zoom-in on the big axes
axbig.XLim = [50 100];
axbig.YLim = [100 150];
% Optional: Add a rectangle to the small axes to reflect the big axes
% limits
rectangle(axsmall, 'Position', [50 100 50 50], 'LineWidth',1, 'EdgeColor','r');
If you want to get clever, you can use the LimitsChangedFcn to update the rectangle when the zoom of the big axes change.
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Benjamin Kraus am 22 Jul. 2024 um 19:40
I can't tell if you were trying to do the reverse: Soom the small image, so here's the reverse option.
t = tiledlayout(20,20);
% Create one big axes that fills the entire layout.
axbig = nexttile(t, [20 20]);
% Add the image to the big axes.
image(axbig, im);
% Now add a small axes in the upper right corner of the big axes.
axsmall = copyobj(axbig, t);
n = tilenum(t, 2, 12);
axsmall.Layout.Tile = n;
axsmall.Layout.TileSpan = [8 8];
% Now zoom-in on the small axes
axsmall.XLim = [75 100];
axsmall.YLim = [100 125];
% Hide the ticks on the small axes
xticks(axsmall,[]);
yticks(axsmall,[]);
% Add a rectangle to the small axes to reflect the big axes
% limits
rectangle(axbig, 'Position', [75 100 25 25], 'LineWidth',1, 'EdgeColor','r');

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by