Zooming a portion of figure in a figure.

Dear friends Can any boby will tell the method of zooming only a portion of a particular figure, in figure window. This is mainly required to indicate the detail of a particular segment of a figure. Please reply...

 Réponse acceptée

Kye Taylor
Kye Taylor le 28 Mar 2012
Modifié(e) : DGM le 17 Avr 2023
Below is an example that zooms in on a portion of a curve and displays the zoomed in version in the same figure window without using subplot. Let me know if I can clarify any details. Or, please clarify what you're trying to do.
t = linspace(0,2*pi,1000); % values in time
x = cos(t); % a sinusoid
perturbation = 0.1*exp((-(t-5*pi/4).^2)/.01).*sin(200*t); % a perturbation
signal = x+perturbation; % a signal to plot
% plot signal on new figure
figure,plot(t,x+perturbation)
xlabel('time'),ylabel('signal')
% create a new pair of axes inside current figure
axes('position',[.65 .175 .25 .25])
box on % put box around new pair of axes
indexOfInterest = (t < 11*pi/8) & (t > 9*pi/8); % range of t near perturbation
plot(t(indexOfInterest),signal(indexOfInterest)) % plot on new axes
axis tight

14 commentaires

Cagas Akalin
Cagas Akalin le 18 Avr 2015
Thanks Kate,
It helped a lot. Please keep it go :))
Ali Uppal
Ali Uppal le 20 Avr 2015
@ Kye Taylor, so simple and so effective. Its very helpful. Thanks
Upendra Adhikari
Upendra Adhikari le 3 Nov 2016
Thanks it helped me alot.
Bin Xu
Bin Xu le 28 Nov 2016

Thanks, it cures my headache.

Shaik Ahmad
Shaik Ahmad le 27 Déc 2016
How can we do it for dynamic positions, that means if we move the small control box the zoomed portion of that respective position we need to see.
David Torres
David Torres le 16 Fév 2019
Thanks it helped me in my thesis
Brian Yanbo Wang
Brian Yanbo Wang le 25 Mar 2019
THANK YOU SO MUCHH!
moe moe
moe moe le 25 Avr 2020
Thanks a lot
govindan
govindan le 22 Jan 2021
thanks you sir
idrees khan
idrees khan le 21 Avr 2021
how can we do zooming of figues in multiple plots?
AVINASH PANDEY
AVINASH PANDEY le 12 Juin 2021
Cesim Dumlu
Cesim Dumlu le 25 Mai 2022
@Kye Taylor Does this work with polarplot ?
Namhyoung Kim
Namhyoung Kim le 16 Oct 2022
This is wonderful! Thanks a lot :D
Hello, Kye Taylor,
Do you know if is it posible to create two zoom boxes? I think that if you use "box on" for the second time it may replace the first one... am I right?
How would you do that?
Thanks in advance.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 12 Juin 2021

1 vote

See attached zooming demo.

3 commentaires

line 51 of that demo:
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
At that point in the script, it generates a window that spans all available workspace display area obscuring everything in sight, with Ok/Quit buttons beyond the screen edge. How do I contro this behavior?
(it's a cool demo, and thanks for posting it. but i'm not used to doing anything programmatically with the UI)
@jessupj it does not do that for me. Try restarting MATLAB. What happens if you just do this by itself in the command window (not in the zoom script)?
message = 'Click Continue';
button = questdlg(message, 'Continue?', 'OK', 'Quit', 'OK');
it happens in a fresh workspace/restarted matlab. a larger-than-multi-monitor-desktop dialog box with buttons that appear outside the viewable window is generated.
so i guess this a question about start/env settings. i have the following possibly relevant settings in my startup script:
set(0,'DefaultFigureVisible','on');
set(0,'DefaultFigureColor',[1 1 1]);
set(0,'DefaultFigureUnits','Normalized');
set(0,'DefaultFigurePosition',[ 0.01 0.7 0.45 0.21 ]);

Connectez-vous pour commenter.

Catarina Figueira
Catarina Figueira le 19 Mai 2018

0 votes

What if tou have several 'errobar' graphs in the same figure (using holy on)? how can I define 'indexOfInterest' with more then one 't'?

Catégories

En savoir plus sur Data Exploration dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by