How can I change the colour of specific bars in a bar graph

1 次查看(过去 30 天)
Hi,
I want to change the colour of the bars in a bar graph according to a category that each of the variables fall into.
For example, there are 25 variables (25 bars on my bar graph). Bars 1 -7 are a category, 8 - 10, 11- 9 a, 20-22, and 23-25.
Here are the values for the y-axis:
0.3593, -1.2546, 0.9986, 4.1348, -2.3126, -0.2999, -2.8599; (genetics category)
6.7126, -1.9890, -1.9099; (biomarkers category)
8.8851, 8.5652, 6.2261, 4.5569, 7.0883, 9.5378, 7.5932, 14.9368, 15.7487; (cognitive category)
-9.7093, -6.9533, -5.8677; (psychological category)
-1.6640, -1.1083, -0.9188; (vascular cateogory)
*Attached is what the current graph looks like in one colour

采纳的回答

Doddy Kastanya
Doddy Kastanya 2020-12-17
You can create a handle on the graph and replace the properties accordingly. Here is an example.
>> x=[1:10];
>> b=bar(x);
>> b.FaceColor='flat';
>> b.CData(2,:)=[0.5 0 0.5];
>> b.CData(6,:)=[0.3 0.2 0.5];
>> b.CData(10,:)=[0.1 0.7 0.2];
The last three lines changes the color of the second, sixth, and last bar.
I hope this helps.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by