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

조회 수: 4 (최근 30일)
Jorn
Jorn 2013년 2월 19일
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

답변 (2개)

José-Luis
José-Luis 2013년 2월 19일
편집: José-Luis 2013년 2월 19일
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 2013년 2월 19일
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!

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by