How does the indexing of stacked bars work?

27 ビュー (過去 30 日間)
Burak Soydas
Burak Soydas 2019 年 6 月 3 日
コメント済み: Burak Soydas 2019 年 6 月 3 日
Hello,
I am trying to understand how the indexing of stacked bars work. I have a plot with 2 stacked bars but am only able to color the stacks of them the same.
When I use for example b(1,i).FaceColor = [0 0 0] it works but just like I said before I can only color both stacked bars stacks the same. If I use b(2,i) = [ 0 0 0] ( I thought that the first number refers to the number of stacked bars, while the i refers to the individual stacks) I get the following error:
Unrecognized property 'FaceColor' for class 'matlab.graphics.GraphicsPlaceholder'.

採用された回答

Adam Danz
Adam Danz 2019 年 6 月 3 日
You can set individual colors by using an rgb matrix, one color for each bar within the current stack. The FaceColor should be set to 'flat' as well.
Here's a demo:
a = randi(20,4,2); %4 bars, 2 stacks
H=bar(a, 'stacked');
%Set the bottom stack to random colors
colr = rand(4,3);
H(1).FaceColor = 'Flat';
H(1).CData = colr;
%Set the top stack to random colors
colr = rand(4,3);
H(2).FaceColor = 'Flat';
H(2).CData = colr;
  1 件のコメント
Burak Soydas
Burak Soydas 2019 年 6 月 3 日
Hello,
this helped me, thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by