Question about the axis of a figure

조회 수: 1 (최근 30일)
Sam
Sam 2015년 1월 4일
편집: Star Strider 2015년 1월 4일
On the x-axis I have 'number of subjects'. But the axis goes from 0 - 0.5 - 1 - 1.5 - ... Since 1.5 subjects doesn't exist, I want to get rid of these number with the comma. How do I do this?

채택된 답변

Star Strider
Star Strider 2015년 1월 4일
편집: Star Strider 2015년 1월 4일
You need to set the specific 'XTick' locations.
Example:
figure(1)
subplot(2,1,1)
scatter(rand(10,1)*3, rand(10,1)*2, 'pb')
grid
subplot(2,1,2)
scatter(rand(10,1)*3, rand(10,1)*2, 'pb')
grid
xt = get(gca, 'XTick');
set(gca, 'XTick', floor(min(xt)):ceil(max(xt)))
To illustrate:

추가 답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 1월 4일
편집: Geoff Hayes 2015년 1월 4일
Sam - you will need to maipulate then ticks and tick labels for the x-axis. Try running the following statements
xticks = get(gca,'XTick');
xtickLabels = get(gca,'XTickLabel');
Both of these statements should return vectors/arrays of the positions and labels of the x-axis ticks respectively. Since you want to remove every other label (due to the 0.5), then just reset these two properties if the x-axis using every other element only as
set(gca,'XTick',xticks(1:2:end), 'XTickLabel',xtickLabels(1:2:end));
Note that 1:2:end means start at the first element (at index 1) and jump by two until the end is reached. gca is the handle to the current axis (g is for get). The above may require some changes given your version of MATLAB, but try it out anyway.
EDIT
If xtickLabels is a character array, then the above set should be replaced with
set(gca,'XTick',xticks(1:2:end), 'XTickLabel',xtickLabels(1:2:end,:));
  댓글 수: 2
Sam
Sam 2015년 1월 4일
I tried it, but it doesn't work...
Geoff Hayes
Geoff Hayes 2015년 1월 4일
Sam - could you clarify what you mean by it doesn't work? If xtickLabels is a character array, then you may need to replace the set with
set(gca,'XTick',xticks(1:2:end), 'XTickLabel',xtickLabels(1:2:end,:));

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

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by