Filter löschen
Filter löschen

axis tight manipulation

21 Ansichten (letzte 30 Tage)
douglas
douglas am 24 Apr. 2012
Bearbeitet: KSSV am 9 Feb. 2024
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');

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 25 Apr. 2012
You could do something like
set(AX(2), 'YLIM', [min(ROC(:)), max(ROC(:))]);
  5 Kommentare
douglas
douglas am 25 Apr. 2012
Bearbeitet: KSSV am 9 Feb. 2024
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 am 25 Apr. 2012
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...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Two y-axis finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by