Zooming a portion of a plot

Good evening to all,
I am a beginner in Matlab programming. I have a problem related to the plot of figures. Indeed, I want to see how a numerical analysis error evolves as a function of time, so the error function is concentrated around the origin on the y axis. How can I zoom in on this part of the plot? I have tried ylim([ ]) but I am not satisfied because there is a rapid decay that I can't see, so a zoom that keeps the coordinates of the points will be useful.
Best regards,

5 Comments

Would be glad to help if you could share some data / code .
figure()
syms t;
n=20000;
b=[-10 10];
h=abs(b(2)-b(1))/(n+1);
I=[1 1 1];
K=[10^4 10^4 10^4];
zeta=30;
xx1=b(1):h:b(2);
yy1=generateG(b,n,zeta,I);
yy1=cosh(zeta*t)*yy1;
yy1=subs(yy1,t,xx1);
yy2=generateG(b,n,zeta,K);
yy2=cosh(zeta*t)*yy2;
yy2=subs(yy2,t,xx1);
p1 = plot(xx1,yy1,'r');
hold on;
p2 = plot(xx1,yy2,'g');
hold off;
%ylim([0 10^(-2)]);
%xlim([-6.2 6.2]);
%yticks([0 10^(-10) 10^(-8) 10^(-6) 10^(-4) 10^(-2)]);
h = [p1;p2];
xlabel('z')
ylabel('Integrand(z)')
%axis ([-0.5 0.5 0 10^(-6)])
set(gca,'YTick',[10^(-11) 10^(-10) 10^(-9) 10^(-8) 10^(-7) 10^(-6)]);
title('Integrands in term of z for n=200 b=[-10 10]')
legend('I=K=[1 1 1]','I=K=[100 100 100]');
As you can see, I used set(gca,'YTick',[10^(-11) 10^(-10) 10^(-9) 10^(-8) 10^(-7) 10^(-6)]); for that but I can't see any changing. My goal is to see the y axis even for small values of y
Could you share the plotted data as mat file ?
I don't have the symbolic toolbox

Sign in to comment.

Answers (1)

Hi,
As per my understanding you wanted to zoom at a particular portion of the plot to get a clearer picture of that portion. In that case you can use
zoom function: The zoom function allows you to interactively zoom in and out of a plot using the mouse. When you call this function, the cursor turns into a magnifying glass with a plus sign. Clicking and dragging a rectangular area of the graph will zoom in on that area. Pressing the "Alt" key while clicking and dragging will zoom out instead. The zoom function also returns a handle to a zoom object that you can manipulate programmatically if you need to.
For example:
x = linspace(0,10,1000);
y = sin(x);
plot(x,y);
zoom on % Enables interactive zooming on the plot
or alternatively use the magnifying button on the top of the plot to enable this function.
You can also look into this answer if you need a different kind of zoom for your purpose Zooming a portion of figure in a figure. - MATLAB Answers - MATLAB Central (mathworks.com)

Categories

Products

Release

R2023a

Asked:

on 17 Apr 2023

Answered:

on 23 May 2023

Community Treasure Hunt

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

Start Hunting!