Feed on
Posts
Comments


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′);


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

6 Responses to “how to make a transparent histogram in matlab”

  1. on 27 Mar 2011 at 5:52 pm Chris Schwartz

    Thank you, this was quite helpful.

  2. on 05 Jun 2011 at 2:35 pm Jefferson

    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.

  3. on 01 Jul 2011 at 9:41 pm toto

    yes. that is work in my chart. thank for sharing

  4. on 19 Jul 2011 at 12:34 pm Srini

    Thanks for the trick :-)

  5. on 26 Aug 2011 at 11:14 am kevho1

    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

  6. on 08 Sep 2011 at 2:01 pm anon

    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′);

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.