Plot 2 categorical histograms side by side on the same figure using histogram()
Afficher commentaires plus anciens
Hi,
I want to plot two (2) categorical histograms on the same figure side by side using the histogram() function.
Follows is a code that plots 2 categorical histograms - but NOT side by side.
What I need is to plot the 2 histograms - such that every red bin will be after its blue bin respectively.
I searched the documentation and programming forums, but didn't find something.
Doe's anyone has a sugestion ?
% init histo arrays
ha_01 = zeros(1,99); % histo array 01
ha_02 = zeros(1,66); % histo array 02
% fill ha_01
for i = 1:99
ha_01(i) = mod(i-1,3);
end
% fill ha_02
for i = 1:66
ha_02(i) = mod(i-1,3);
end
%define categories for the first histogram (cat_01, cat_02 and cat_03)
h_01_cat = categorical(ha_01,[0 1 2],{'cat 01','cat 02','cat 03'});
%define same categories for the second histogram
h_02_cat = categorical(ha_02,[0 1 2],{'cat 01','cat 02','cat 03'});
%plot the categorical histogram for condition 01 AND condition 02
h_01 = histogram(h_01_cat,'BarWidth',0.25);
h_01.FaceColor = 'blue';
h_01.FaceAlpha = 1;
hold on;
h_02 = histogram(h_02_cat,'BarWidth',0.25);
h_02.FaceColor = 'red';
h_02.FaceAlpha = 1;
hold off;
grid on;
legend('Cond 01','Cond 02');

Thank you,
Shamai Saltsberger
Réponses (1)
shamai saltsberger
le 20 Jan 2022
0 votes
Catégories
En savoir plus sur Histograms 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!