change color of bar plot
1 次查看(过去 30 天)
显示 更早的评论
how can i change my bar plot and define legend like follwing picure ?
0 个评论
回答(2 个)
Sulaymon Eshkabilov
2023-2-20
Here is one example how to get such bar chart:
y = [12 22 23; 21 25 26; 24 18 19; 22 17 15];
bar(y,'stacked')
legend({'Set # 1', 'Set # 2', 'Set # 3'}, 'Orientation','horizontal')
ax = gca;
ax.YGrid = 'on';
ax.GridLineStyle = '--';
xlabel('Orders')
ylabel('Magnitude')
Voss
2023-2-20
y = [12 22 23; 21 25 26; 24 18 19; 22 17 15];
h = bar(y,'stacked'); % capture the bar objects into variable 'h'
legend({'Set # 1', 'Set # 2', 'Set # 3'}, 'Orientation','horizontal')
ax = gca;
ax.YGrid = 'on';
ax.GridLineStyle = '--';
xlabel('Orders')
ylabel('Magnitude')
% change the bar colors:
h(1).FaceColor = 'k';
h(2).FaceColor = [0 0.5 0];
h(2).FaceColor = 'm';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!