フィルターのクリア

How do I modify colors in a stacked bar graph?

1 回表示 (過去 30 日間)
Dominik
Dominik 2013 年 4 月 9 日
I have a stacked bar graph and would like to color the stacks according to their position in the vector, but each value doesn't always get printed.
m1{1,1}=0.0193; %only a single value in this position
m1{2,1} = [-0.0155 0.0117 -0.0037 -0.0856 0.0180];
m1{1,2} = [-0.0340 -0.02889 -0.0359 -0.1049 -0.0255];
m1{2,2} = [-8.5343e-04 0.0213 0.0129 0 0.0243];
%There are 5 values in each cell. I am stacking these values but I don't want them crossing zero so I plot + and - separately. I want to plot each cell as series in the bar plot (so they should be touching) and then do this for 3 months on the same graph.
cl_colors={'r','y','g','b','c'};
f1p=find(m1{2,1}(m1{2,1}>=0));
f2p=find(m1{2,2}(m1{2,2}>=0));
f1m=find(m1{2,1}(m1{2,1}<0));
f2m=find(m1{2,2}(m1{2,2}<0));
% I was hoping this could be used to define the colors of my stacks. For example, if bar1 plots the numbers from positions 1,3,4 then I want the colors of those stacks to be r,g,b. It's important that the colors always associate with the position in the vector.
bar1=bar([[m1{2,1}(m1{2,1}>=0) zeros(length(m1{2,1}(m1{2,1}<0)),1)'];...
[m1{2,2}(m1{2,2}>=0) zeros(length(m1{2,2}(m1{2,2}<0)),1)']],'stack','BarWidth',1,'FaceColor',{[cl_colors(f1p) 'w' 'w' 'w'];[cl_colors(f2p) 'w' }));
hold on
bar2=bar(get(bar1,'XTick'),[[m1{2,1}(m1{2,1}<0) zeros(length(m1{2,1}(m1{2,1}>=0)),1)'];...
[m1{2,2}(m1{2,2}<0) zeros(length(m1{2,2}(m1{2,2}>=0)),1)']],'stack','BarWidth',1,'FaceColor',{[cl_colors(f1m) 'w' 'w' ];[cl_colors(f2m) 'w' 'w' 'w' 'w']}));
% In the above statement (which doesn't work for assigning facecolor), using 'w' based on manual inspection is less than ideal so I am hoping someone has a suggestion for this. The final product should also have m1{1,1} as a single black bar. Based on other posts, I tried to get(bar1,'Children') and then changing the facecolor or cdata but to no avail.
Let's say that's the data for Mar, How do I then plot the data for Apr in the same configuration spaced away from the Mar series? Thanks!

回答 (0 件)

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by