merge three barh (stacked)
Afficher commentaires plus anciens
I have one table with different regions and data. Each color outlines different data that it should be one bar.
For example the variable A has one bar (stacked) with values from column "B" to "K". Then always the variable A has the bar (stacked) from column "L" to "U" and at the end the third bar with value from "V" to "AE".
t = readtable('Cartel2.xlsx')
I tried this code, but it is not clear, too long
x = [1 2 3];
y = [0.18 0.54 0.50 0.74 0.30 2.18 0.64 3.75 0.56 0.62; 0.63 1.10 1.39 1.86 1.59 0.71 0.67 0.68 0.74 0.63; 4.12 0.00 0.08 0.00 0.05 1.45 0.00 0.00 0.00 0.30];
barh(x,y,'stacked')
I would like to get bar (stacked) sequential, it is possible?
Réponse acceptée
Plus de réponses (1)
Mathieu NOE
le 12 Avr 2022
hello Rachele
try this !
you get now one figure (plot) per variable , 20 in total)
all the best
t = readcell('Cartel2.xlsx');
var_names = t(:,1);
data = cell2mat(t(:,2:end)); % 3 groups of 10 rows
for ci = 1:numel(var_names)
y = data(ci,:);
yy = reshape(y,3,10);
figure(ci),
barh(x,yy,'stacked')
title(['variable :' var_names(ci) ]);
end
4 commentaires
Rachele Franceschini
le 12 Avr 2022
Mathieu NOE
le 12 Avr 2022
okay
see there
I could get this - may still need to further improve the legend and see how to change it to horiz bar

clc
clearvars
t = readcell('Cartel2.xlsx');
var_names = t(:,1);
data = cell2mat(t(:,2:end)); % 3 groups of 10 rows
for ci = 1:numel(var_names)
y = data(ci,:);
yy(ci,:,:) = reshape(y,3,10);
end
groupLabels = var_names';
h = plotBarStackGroups(yy, groupLabels);
% Chance the colors of each bar segment
colors = jet(size(h,2)); %or define your own color order; 1 for each m segments
colors = repelem(colors,size(h,1),1);
colors = mat2cell(colors,ones(size(colors,1),1),3);
set(h,{'FaceColor'},colors)
Rachele Franceschini
le 12 Avr 2022
Mathieu NOE
le 13 Avr 2022
My pleasure !
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



