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

4 次查看(过去 30 天)
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