条形图透明度不起作用

时间:2016-01-20 16:37:50

标签: matlab plot

我将两个频率条形图绘制在一起,我希望其中一个条形图是透明的。我试过这个:

[n,xout] = hist(data1,10); %Use 10 bins for the histogram
B1 = bar(xout,n/sum(n),'b'); %relative frequency is n/sum(n)
hold on
[n,xout] = hist(data2,10); %Use 10 bins for the histogram
B2 = bar(xout,n/sum(n),'r'); %relative frequency is n/sum(n)
ch = get(B2,'child');
set(ch,'facea',.4)

然而,第二幅图表似乎并不透明。我有什么遗失的吗?

修改

get(B2)的输出:

Annotation: [1x1 matlab.graphics.eventdata.Annotation]
             BarLayout: 'grouped'
              BarWidth: 0.8000
              BaseLine: [1x1 Baseline]
             BaseValue: 0
          BeingDeleted: 'off'
            BusyAction: 'queue'
         ButtonDownFcn: ''
              Children: []
              Clipping: 'on'
             CreateFcn: ''
             DeleteFcn: ''
           DisplayName: ''
             EdgeColor: [0 0 0]
             FaceColor: 'flat'
      HandleVisibility: 'on'
               HitTest: 'on'
            Horizontal: 'off'
         Interruptible: 'on'
             LineStyle: '-'
             LineWidth: 0.5000
                Parent: [1x1 Axes]
         PickableParts: 'visible'
              Selected: 'off'
    SelectionHighlight: 'on'
          ShowBaseLine: 'on'
                   Tag: ''
                  Type: 'bar'
         UIContextMenu: []
              UserData: []
               Visible: 'on'
                 XData: [1x10 double]
             XDataMode: 'manual'
           XDataSource: ''
                 YData: [0.5333 0.1778 0.0444 0.0889 0.0889 0.0222 0 0.0222 0 0.0222]
           YDataSource: ''

1 个答案:

答案 0 :(得分:2)

那是因为B2没有任何孩子,所以ch是空的(至少在R2015B中)。

您可以使用例如

直接更改FaceAlpha属性
B2 = bar(xout,n/sum(n),'r','facea',.4);

而不是寻找它的孩子。