필터 지우기
필터 지우기

Customize "XTickLabel" location

조회 수: 23 (최근 30일)
Rosie
Rosie 2017년 8월 21일
답변: Jason Kulpe 2018년 6월 21일
I'm using names rather than values for my x-axis using the script below:
set(gca,'XTickLabel',{'P1', 'P2', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10','P11', 'P12', 'P13', 'Population Mean'});
However, I want my last XTickLabel to be further to the right so it stands out from the rest of the values. I tried different things like blank ' ' labels or placing extra spaces eg. '<space> Population Mean' but it didn't work. Any suggestions?
Thanks,
Rosie
  댓글 수: 3
Rosie
Rosie 2017년 8월 21일
I actually used spaces before to put extra space between XTixkLabels, but don't know why it doesn't work now.
Walter Roberson
Walter Roberson 2017년 8월 21일
plot(1:20)
ax = gca;
ax.XTick = [1 2 4 5 6 7 8 9 10 11 12 13 14];
ax.XTickLabel = {'P1', 'P2', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10','P11', 'P12', 'P13', 'Population Mean'};
pause(3);
ax.XTickLabel = {'P1', 'P2', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10','P11', 'P12', 'P13', ' Population Mean'};
In the first version, the 'Population Mean' label will greatly overlap the other labels. Then when it is changed to have a number of spaces before it, you will see it move further right, without having changed the XTick

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

답변 (2개)

Steven Lord
Steven Lord 2017년 8월 21일
% Create a new figure and an axes
figure;
ax = axes;
% Change the X limits of the axes
xlim(ax, [1 15]);
% Change the locations of the tick labels
ax.XTick = [1:5 12];
% Change the tick labels themselves
ax.XTickLabel = {'x1', 'x2', 'x3', 'x4', 'x5', 'the rest'};
Note that I've exaggerated the space between the labels 'x5' and 'the rest'; if you just want a little bit of separation maybe put the labels at [1:2:9 12] instead of [1:5 12].

Jason Kulpe
Jason Kulpe 2018년 6월 21일
I found a way to modify the position of the YAxis for a particular application. Its not exactly what you were looking for but it might help you: here

카테고리

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