axes problem in a plot

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.

 채택된 답변

Matt Fig
Matt Fig 2012년 11월 15일

0 개 추천

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

joo
joo 2012년 11월 15일
here in your code you are fixing values right?
how can i set the axes limits to be a certain percent of the data, as you suggested?
thank you very much.
Matt Fig
Matt Fig 2012년 11월 15일
There are several things you could do. One would be to add a certain percent to the endpoints. Another is to add a certain percent to the range. I show the second option here:
x = pi:.001:2*pi;
y = sin(x).*x.^2 + 1;
plot(x,y)
mnx = min(x);
mxx = max(x);
mny = min(y);
mxy = max(y);
dx = mxx-mnx;
dy = mxy-mny;
axis([mnx - .1*dx,...
mxx + .1*dx,...
mny - .1*dy,...
mxy + .1*dy])
joo
joo 2012년 11월 15일
i see... but following your advices, this code shouldn't work? :
grid on;
axis([(min(xxK)*0.120),...
(max(xxK)*0.120),...
(min(zzK)*0.120),...
(max(zzK)*0.120),...
(min(yyK)*0.120),...
(max(yyK)*0.120)])
Matt Fig
Matt Fig 2012년 11월 15일
Did you try it? How could I tell if that would work when you have not defined xxK, yyK, zzK etc.? Notice that my example was complete enough for you to copy and paste to examine the results....
joo
joo 2012년 11월 15일
yes, i tried yours and in fact is working perfectly. but i was trying a smaller code. if xxK, yyK, zzK are defined in the workspace isn't it enough? thank you so much.
Matt Fig
Matt Fig 2012년 11월 15일
"if xxK, yyK, zzK are defined in the workspace isn't it enough?"
Enough for what? You will get some results, assuming those are real numeric variables, but I still cannot tell if they are the results you want. Only you can tell, because only you can see the data and the results.
Good luck!
joo
joo 2012년 11월 15일
편집: joo 2012년 11월 15일
ok i understand. but just tell me this last question: when i use your code the axes of the plot produced are not numerated from the beggining? can i fix this?
(in your plot it is almost invisible but for me, as i am working with big numbers the plot shows a big empty space in the axes)
thank you so much.
Matt Fig
Matt Fig 2012년 11월 15일
편집: Matt Fig 2012년 11월 15일
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 2012년 11월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

joo
2012년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by