How an I manipulate top and bottom x axes individually?

조회 수: 84 (최근 30일)
Rod Letchford
Rod Letchford 2020년 8월 30일
답변: Rod Letchford 2020년 8월 31일
I want to control the x axis top and bottom individually / separately.
Specifically I want to point the bottom x axis ticks out and the top x axis ticks in ( and point left y axis out and right y axis in).
  댓글 수: 2
Rod Letchford
Rod Letchford 2020년 8월 30일
Currently using R2020a Student.
dpb
dpb 2020년 8월 30일
The 'TickDirection' property is global for the X- and Y- axis objects; there's insufficient granularity of properties to modify one but not the other.
You could make two axes, and set one 'in' and one 'out', but then both would show anyway...
Don't see any way to do this other than to physically draw ticks where wanted if it's that important to go to the trouble.

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

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 8월 30일
Actually, dpb's suggestion of 2 axes should work as long as you don't turn "box on", and you may need to sync their positions if you do things like add axis labels, etc.
fig = figure;
ax(1) = axes(fig,'Color','none');
ax(2) = axes(fig,'Color','none');
ax(2).YAxisLocation = 'right';
ax(2).XAxisLocation = 'top';
ax(2).XAxis.TickDirection = 'out'
ax(1).YAxis.TickDirection = 'out'
  댓글 수: 1
dpb
dpb 2020년 8월 30일
" 2 axes should work as long as you don't turn "box on"
Ah-so! Indeed. Didn't think about box leaving off the opposite side ticks...good catch.

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

추가 답변 (1개)

Rod Letchford
Rod Letchford 2020년 8월 31일
Alex,
This works really well, thanks. My slight adjustment:
fig = figure;
ax(1) = axes(fig,'Color','none');
ax(2) = axes(fig,'Color','none');
ax(1).XAxisLocation = 'bottom';
ax(2).XAxisLocation = 'top';
ax(1).YAxisLocation = 'left';
ax(2).YAxisLocation = 'right';
ax(1).XAxis.TickDirection = 'out'; % Bottom
ax(2).XAxis.TickDirection = 'in'; % Top
ax(1).YAxis.TickDirection = 'out'; % Left
ax(2).YAxis.TickDirection = 'in'; % Right
The last and third last lines are redundant since by default the ticks are 'in', but I put them there so its easy to change.

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by