Hello,
I am trying to set my axis to 'tight'. The plot has 2 Y axes using the plotyy function, and I want my second axis to be 'tight'. Whe I set it to tight, it sets both the Y and X Lims to fill in the maximum space alotted in the plot. IS there a way to only have the YLim set to tight, while holding the same default or 'auto' limits for X? I also would like it to rescale my limits in Y (it currently messes it up after the axis tight command)
Here is what I have so far, which messes up my limits in Y
subplot(6,1,6,'align'); [AX,H1,H2] = plotyy(time(1:end-1),Altitude(1:end-1),time(1:end-1),ROC,'plot');
axis(AX(2),'tight');

 채택된 답변

Daniel Shub
Daniel Shub 2012년 4월 25일

0 개 추천

You could do something like
set(AX(2), 'YLIM', [min(ROC(:)), max(ROC(:))]);

댓글 수: 5

douglas
douglas 2012년 4월 25일
I had thought to try something like that, it works and looks great thanks. The only other issue I would have now is that the Ylim is not necessarily displayed, sometimes it has a Ymin or a Ymax shown but not both.
Daniel Shub
Daniel Shub 2012년 4월 25일
I am not sure what you mean? I am guessing there is no tick at the max or min value. You can set the ticks, but then the numbers will not be "nice" looking. You cannot have tight limits and be guaranteed integer/small numbers.
Daniel Shub
Daniel Shub 2012년 4월 25일
If this has solved the original question, please accept it. If there is a new question, ask it as such. If this was helpful, but did not answer the question fully, then please vote for it.
douglas
douglas 2012년 4월 25일
편집: KSSV 2024년 2월 9일
I added an if else to make the smaller values look ok and the larger ones readable, but your right, with tight limits you don't get pretty values for the y axis.
set(AX(2), 'YLIM', [min(ROC(:)), max(ROC(:))]);
if max(ROC(:))>100
set(AX(2),'YTick',min(ROC(:)):3000:max(ROC(:)));
else
set(AX(2),'YTick',min(ROC(:)):5:max(ROC(:)));
end
Daniel Shub
Daniel Shub 2012년 4월 25일
If you use min(ROC(:)):(max(ROC(:))-min(ROC(:)))/N:max(ROC(:)) you will always get N ticks (maybe N+1). If you round the min and max to a predetermined number of digits, you can also control for that...

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

추가 답변 (0개)

카테고리

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

제품

질문:

2012년 4월 24일

편집:

2024년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by