How to change the transparency of bars in a barseries plot?

4 views (last 30 days)
Hi,
Because I would like to plot 2 barseries on top of each other, I need to make the bars of 1 barserie a little bit transparant.
I have tried this using the Alpha function, but it returns an error:
Error using specgraph.barseries/set The name 'FaceAlpha' is not an accessible property for an instance of class 'barseries'.
Another solution that I found, but didnt work for me:
v1 = rand(81,1); c1 = [1 0 1]; H1=histfit(v1); set(H1(2),'Color',c1); set(H1(1),'FaceColor',c1); hpatch = get(H1(1),'children'); set(hpatch,'FaceAlpha',.25);
The transparency i not influenced by the code.
Any ideas on how I need to go about in this matter? I have Matlab 7.13 / R2011b.
Thanks,
Jorn

Answers (2)

José-Luis
José-Luis on 19 Feb 2013
Edited: José-Luis on 19 Feb 2013
It seems to me that you are not passing the correct value for the handles of the patch:
v1 = rand(81,1);
c1 = [1 0 1];
H1=histfit(v1);
set(H1(2),'Color',rand(1,3));
set(H1(1),'FaceColor',rand(1,3));
set(H1(1),'FaceAlpha',.25);
EDIT
Based on your comment, this might be what you are looking for:
bH = bar(randn(10));
get(bH,'Type') %For illustration purpose only.
pH = arrayfun(@(x) allchild(x),bH);
set(pH,'FaceAlpha',0.25);
In the future, please place comments to an answer under the answer, otherwise it might get confusing for other people joining the discussion.

Jorn
Jorn on 19 Feb 2013
Jose-Luis, you are correct. But your solution does not work for barseries charts: it only works for single bars. If I use your solution on my barseries chart, the error returned is:
Error using specgraph.barseries/set The name 'FaceAlpha' is not an accessible property for an instance of class 'barseries'.
So I hope there's another solution!

Categories

Find more on App Building in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!