Why my barchart's 'xticklabel' is skipping the odd numbers and adding 0 and another number at the end?

3 ビュー (過去 30 日間)
This is my code where i expect 1,2,3,4,5 as "xticklabel". But MATLAB is adding 0 and 6 at the end and skipping 1,3,5!
EFV = [34.4263250184944312;
55.7029868436263982;
56.9140938310396862;
60.0977661822922329;
15.4772478454135065];
figure(1)
title(' (EFV)','fontsize',10,"fontweight","Bold");
xlabel(' Mechanisms')
ylabel('(EFV)')
box on
hold on
for i = 1:length(EFV)
h=bar(i,EFV(i));
if EFV(i) == min(EFV)
set(h,'FaceColor','b');
elseif EFV(i) == max(EFV)
set(h,'FaceColor','r');
else
set(h,'FaceColor','k');
end
end

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 1 月 14 日
Well, matlab has its own way to select and adjust what tick-marks should be used. What you can add at the end is something like this:
xticks = 1:numel(EVF);
set(gca,'XTick',xticks)
HTH
  2 件のコメント
Mr. 206
Mr. 206 2019 年 1 月 14 日
Thanks.
How can i remove additional space at the beginning and at the end?
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 1 月 14 日
I typically use something like:
edge_width = 0.1;
xmin = 1;
xmax = numel(EVF);
ax = axis;
axis([xmin-edge_width xmax+edge_width ax(3:4)])
HTH

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

その他の回答 (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