How can I assign different colors to different bins of a single "bar/barh object"?

1 回表示 (過去 30 日間)
cui,xingxing
cui,xingxing 2021 年 7 月 11 日
回答済み: Ive J 2021 年 7 月 11 日
How can I assign different colors to different bins of a single "bar/barh object"?
For example, the first example in the official documentation.
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(y)
This figure has 11 bins, this case through the "faceColor" property set to a color at the same time, but how to set the display for 11 different colors it ? (no Groups of Bars)

採用された回答

Ive J
Ive J 2021 年 7 月 11 日
Well, you just needed to go through the doc for bar.
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
h = bar(y, 'FaceColor', 'flat', 'CData', randi([0, 1], numel(y), 3)); % change CData

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by