Change number of xTicks

79 ビュー (過去 30 日間)
Rui
Rui 2014 年 12 月 27 日
コメント済み: Star Strider 2014 年 12 月 27 日
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 :
But what I'm getting is this :
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 12 月 27 日
編集済み: Azzi Abdelmalek 2014 年 12 月 27 日
Where is your code? a code that we can test
Rui
Rui 2014 年 12 月 27 日
編集済み: Rui 2014 年 12 月 27 日
names = {'Peter'};
w = 0.5; % Rectangle Width
figure(1);
axis([0 1 0 20]);
rectangle('Position',[1-w/2 1 0.5 2], 'LineWidth',2);
ax = gca;
set(ax, 'xticklabel', names);

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2014 年 12 月 27 日
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.
  2 件のコメント
Rui
Rui 2014 年 12 月 27 日
It is exactly that! Thank you so much
Star Strider
Star Strider 2014 年 12 月 27 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by