Change number of xTicks
46 views (last 30 days)
Show older comments
Hello, I am trying to make a graph like a boxplot using rectangles. I draw them in the figure to represent intervals. What I want is to appear something like, in the x-axis the name of the persons and in the y axis the intervals of the numbers they have.
For example:
If Peter has [1,2] and [3,4] I want the graph something like this :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146609/image.png)
But what I'm getting is this :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146610/image.png)
I use: ax = gca; set(ax, 'xticklabel', names);
to change the x-axis but what I need now is for the names to appear only once not many times.
Can anyone help me?
2 Comments
Azzi Abdelmalek
on 27 Dec 2014
Edited: Azzi Abdelmalek
on 27 Dec 2014
Where is your code? a code that we can test
Accepted Answer
Star Strider
on 27 Dec 2014
You will have to experiment with your code, but when you set 'XTickLabel' values it is necessary to specify the 'XTick' locations as well.
For example:
names = {'Peter' 'Jürgen' 'Elizabeth' 'Jennifer'};
figure(1)
scatter(rand(10,1), rand(10,1))
xtk = get(gca, 'XTick'); % Get 'XTick' Data For Information
set(gca, 'XTick', [1:2:8]/10, 'XTickLabel', names)
The line for ‘xtk’ will help you determine where the plotting command puts the 'XTick' values. It is helpful, but may not be necessary in your final code.
More Answers (0)
See Also
Categories
Find more on Annotations 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!