I've seen this question asked before but there appears to be no solution so am just wondering if it is at all possible.
I have a bar plot in MatLab and have set the transparency:
B = bar(x,y,'stacked');
set(B(1),'facecolor',[0 0.3906 0])
set(B(2),'facecolor',[0.5625 0.9297 0.5625])
ch1 = get(B(1),'child');
set(ch1,'facea',.5)
ch2 = get(B(2),'child');
set(ch2,'facea',.5)
And I would like the transparency in the plot to be reflected in the legend:
BL = legend ((B([1 2])),{'data1','data2'},'fontsize',10);
However, it appears the alpha value in the legend is 1.
Any ideas? Thanks.
Note with the 2014b update a slight change is needed. The information about patches etc. seems now to be held in the "icons" output from the legend command, so you need;
[BL,BLicons] = legend ((B([1 2])),{'data1','data2'},'fontsize',10);
and then
PatchInLegend = findobj(BLicons, 'type', 'patch');
set(PatchInLegend, 'facea', 0.5)
for this to work now. Just spent an hour figuring this out, so thought I'd pass it on:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With