Question about the axis of a figure
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
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:
0 件のコメント
その他の回答 (1 件)
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 件のコメント
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 Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!