Hi all!
%Öffnen des benötigten workspace:
load('sensitivity_analysis.mat');Data = zeros(9,3,3);Data(:,:,1) = production_wo_elec;Data(:,:,2) = production_variable;Data(:,:,3) = usephase;groupLabels = { 'hc small', 'hc medium', 'hc large', 'mix small', 'mix medium', 'mix large','green small','green medium','green large'}; % set labels
plotBarStackGroups(Data, groupLabels); % plot groups of stacked bars
function [] = plotBarStackGroups(Data, groupLabels)%%Plot a set of stacked bars, but group them according to labels provided.
%%Params:
stackData is a 3D matrix (i.e., stackData(i, j, k) => (Group, Stack, StackElement))
groupLabels is a CELL type (i.e., { 'a', 1 , 20, 'because' };)
%%Copyright 2011 Evan Bollig (bollig at scs DOT fsu ANOTHERDOT edu
NumGroupsPerAxis = size(Data, 1);NumStacksPerGroup = size(Data, 2);% Count off the number of bins
groupBins = 1:NumGroupsPerAxis;MaxGroupWidth = 0.65; % Fraction of 1. If 1, then we have all bars in groups touching
groupOffset = MaxGroupWidth/NumStacksPerGroup;figure hold on; for i=1:NumStacksPerGroup Y = squeeze(Data(:,i,:)); % Center the bars:
internalPosCount = i - ((NumStacksPerGroup+1) / 2); % Offset the group draw positions:
groupDrawPos = (internalPosCount)* groupOffset + groupBins; h(i,:) = bar(Y, 'stacked','Facecolor','flat'); set(h(i,:),'BarWidth',groupOffset); set(h(i,:),'XData',groupDrawPos); if i==1 h(1,1).CData=[189/255 183/255 107/255]; h(1,2).CData=[ 77/255 77/255 1]; h(1,3).CData=[173/255 1 47/255]; elseif i==2 h(2,1).CData=[189/255 183/255 107/255]; h(2,2).CData=[ 77/255 77/255 1]; elseif i==3 h(3,1).CData=[189/255 183/255 107/255]; h(3,2).CData=[ 77/255 77/255 1]; h(3,3).CData=[0 0 0]; end end %h=gca;
%h.FaceColor='flat';
%h.CData(2,:)=[.5 0 .5];
hold off; set(gca,'XTickMode','manual'); set(gca,'XTick',1:NumGroupsPerAxis); set(gca,'XTickLabelMode','manual'); set(gca,'XTickLabel',groupLabels); end
What I want to do is: in the first three Groups the middle Elements should be black instead of blue (as they represent small/medium/large amounts of electricity generated with hard coal) while in the groups 7 to 9 the middle Elements should be green instead of blue cause they represent electricity from renewable energy.
Cheers, Sonja
Best Answer