assign particular colour to 2nd bar of the bar plot
1 次查看(过去 30 天)
显示 更早的评论
I have a matrix of 4 elements. I plotted a bar graph. how can I assign red colour for the 2nd bar and blue for remaining 3 bars?
0 个评论
回答(1 个)
Subhadeep Koley
2020-2-4
Hi, use the code below.
clc; close all;
% Define your 4-element matrix
y = [25 75 100 125];
% Plot bar graph
b = bar(y);
% Assign red colour to the second bar
b.FaceColor = 'flat';
b.CData(2,:) = [1 0 0];
Hope this helps!
2 个评论
Subhadeep Koley
2020-2-4
No I meant b.CData(2,:) = [1 0 0]; only.
Which matlab version are you using?
Also, can you show the matrix which you are trying to plot? (I mean you entire code)
It seems the built-in bar() function is being shadowed by a custom function with same name as "bar".
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!