axes problem in a plot

1 view (last 30 days)
joo
joo on 15 Nov 2012
how can i solve the problem of this two images automatically without having to fix the axes range for each plot (i have millions of these plots)?
(problem: axis shoud be for x[0 18]) and for y[-6 6]
(problem: the minimum x and minimum y should be bigger)
thank you so much.

Accepted Answer

Matt Fig
Matt Fig on 15 Nov 2012
You can set the axes limits to be a certain percent of the data or fixed values, depending on what you want.
x = -pi:.001:pi;
y = sin(x).*x.^2;
plot(x,y)
axis([-5 5 -6 6]) % Use this to set the limits as needed
  9 Comments
Matt Fig
Matt Fig on 15 Nov 2012
Edited: Matt Fig on 15 Nov 2012
In that case, something like this might be preferable:
x = pi:.001:2*pi;
y = sin(x).*x.^2 + 1;
plot(x,y)
xt = get(gca,'xtick');
dx = xt(2)-xt(1);
yt = get(gca,'ytick');
dy = yt(2) - yt(1);
pause(1)
axis([xt(1) - dx,...
xt(end) + dx,...
yt(1) - dy,...
yt(end) + dy])
Part of the problem is that we could go on forever trying to make your plot look just like you want it to look. I have tried to provide you with some tools to think about, play with, and apply to your particular data.
joo
joo on 15 Nov 2012
your code works with my data for 2D but when i work in 3D it doesn't. i will send you my code and excel file by email. if you don't mind to take a few minutes to see the problem, i would be very grateful.
if you can't, thank you very much as well for ALL your help and kindness!
thank you so much.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!