how to make a transparent histogram in matlab
July 18th, 2006 by Lawrence David

to make a partially transparent histogram in matlab, use the facealpha setting.
for instance, the following code produces the histogram seen above:
figure
hist(data1,20)
h = findobj(gca,’Type’,'patch’);
set(h,’FaceColor’,'r’,'EdgeColor’,'w’,'facealpha’,0.75)
hold on
hist(data2,20)
h = findobj(gca,’Type’,'patch’);
set(h,’facealpha’,0.75);
ylabel(‘counts’)
xlabel(‘gene-tree-length/species-tree-length’)
legend(‘no HGT’,'HGT’)
title(‘p = 0.5′);
Thank you, this was quite helpful.
Exactly what I was looking for, but when I declare the second (and third etc) h and change facecolor it happens to all the histograms, not just the last one.
yes. that is work in my chart. thank for sharing
Thanks for the trick
Thanks, this is great.
Do you know how to draw a histogram with errorbars, the errorbars depending on the number of points in each bin of the histogram?
If you couuld help, that would be great
Very helpful.
Jefferson:
Unless I am mistaken, findobj will return a vector with handles to all objects that fit the bill. If you want to modify this such that you can use multiple different colors or alphas, refer to each separately. Something like:
figure
hist(data1,20)
hold on
hist(data2,20)
h = findobj(gca,’Type’,’patch’);
set(h(1),’FaceColor’,’r’,’EdgeColor’,’w’,’facealpha’,0.75)
set(h(2),’FaceColor’,’b’,’EdgeColor’,’w’,’facealpha’,0.75)
ylabel(‘counts’)
xlabel(‘gene-tree-length/species-tree-length’)
legend(‘no HGT’,’HGT’)
title(‘p = 0.5′);