Let's say we have 3 datasets of the same size, that we want to plot on the same histogram:
Dataset_1 = [1 1 1 1 1 1 2 2 2 2 3 3];
Dataset_2 = [1 1 1 2 2 2 2 2 2 3 3 3];
Dataset_3 = [1 1 2 2 2 2 3 3 3 3 3 3];
RGB = orderedcolors("gem");
H = rgb2hex(RGB);
figure
h1 = histogram(Dataset_1, 'FaceColor', RGB(1,:),'FaceAlpha',0.8);
hold on;
h2 = histogram(Dataset_2, 'FaceColor', RGB(2,:),'FaceAlpha',0.8);
h3 = histogram(Dataset_3, 'FaceColor', RGB(5,:),'FaceAlpha',0.8);
The output would be the following:
The leftmost bar is "prettier", since the blue bar (Dataset_1, highest value in the first bin) is plotted first, followed by the orange bar (Dataset_2, second highest value in the first bin) and then the green bar (Dataset_3, lowest value in the first bin).
I don't like how the other bars are displayed though, i.e., when the plotting order does not match the bars values.
I tried playing around with the FaceAlpha property but it does not give anything good.
What I want to have, ultimately, is a histogram in which, for each bin, the plot order is defined by the height of the bar for each dataset. First, plot the highest bar, etc. This seems impossible as the plot order is defined by the call order.
Question: Is there a magic trick in your sleeve for doing that?

bar()[hist1,edges1] = histcounts(Dataset_1); bin1 = (edges1(1:end-1) + edges1(2:end))/2; scatter(hist1, bin1); xlim([0,7]); ylim([0.5,3.5]); yticks(1:3); xlabel("count"); ylabel("value");.