Question about the axis of a figure
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 4 Jan 2015
Edited: Star Strider
on 4 Jan 2015
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 Comments
More Answers (1)
Geoff Hayes
on 4 Jan 2015
Edited: Geoff Hayes
on 4 Jan 2015
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 Comments
Geoff Hayes
on 4 Jan 2015
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,:));
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!