Plotting Bar Graphs with just ones group

3 ビュー (過去 30 日間)
Daniele
Daniele 2015 年 8 月 7 日
コメント済み: Star Strider 2015 年 8 月 7 日
Hello everyone, I would like to produce a bar plot composed by grouped bars. The problem rises when i want to plot just one group:
x = [5], y = [2, 4, 7]
because Matlab sees it as a normal bar plot. I've tried to add the 'grouped' otpions but it does not work. The solution in the following link works but does not permit to use the nan padding along the x axis. Do you have a suggestion?

採用された回答

Star Strider
Star Strider 2015 年 8 月 7 日
I’m not certain what result you want, but one option is to play with the axis limits:
x = [5];
y = [2, 4, 7];
figure(1)
hb = bar([x; 2*x], [y; nan(1,3)]);
axis([3 7 ylim])
  2 件のコメント
Daniele
Daniele 2015 年 8 月 7 日
Thank you for your answer. Your solution work but changing the x-axis for me does not work because I cannot change the x-axis (in my particular case)
Star Strider
Star Strider 2015 年 8 月 7 日
This is likely as close as I can get (in R2015a). (If you’re using R2014a or earlier, this requires a different approach,)
The code:
x = [5];
y = [2, 4, 7];
figure(1)
hBar = bar([x; 2*x], [y; nan(1,3)]);
for k1 = 1:size(hBar,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, [hBar(k1).XOffset]'); % Centres Of Bar Groups
ydt(k1,:) = hBar(k1).YData; % Y-Data Of Bar Groups
xdt(k1,:) = hBar(k1).XData; % X-Data Of Bar Groups
hBar(k1).XData(:,2) = [];
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by