how to assign a color to individual bars in a bar chart using a colormap based on a separate series of values?
Show older comments
I have the following 10 x 3 matrix:
1 3.43 0.80
2 3.24 0.10
3 3.20 0.60
4 3.15 0.90
5 3.07 0.70
6 2.82 1.00
7 2.76 0.50
8 2.62 0.70
9 2.61 0.60
10 2.55 0.90
I want to plot this as a bar chart using the first 2 columns, but assign colors to each bar based on its value in the 3rd column, using some form of a colormap, such that the color of each bar reflects the value in the 3rd column.
I can get this far easily:
>> x=matrix(:,1);
>> y=matrix(:,2);
>> bar(x,y)
to get this figure, no problem:

But how do I now change the color of each bar based on its corresponding value in the 3rd column of the matrix, using a colormap?
Accepted Answer
More Answers (1)
Monika Phadnis
on 28 Jun 2019
0 votes
Check the dimensions of the matrices you are concatenating. Since the vals2colormap returns a 100x3 matrix (considering you wanted to map 100 entries), the dimension of y values should 100xsome_value.
Take a transpose or reshape the matrices and try again.
1 Comment
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!