2016-01-20 92 views
1

我正在繪製兩個頻率條形圖,彼此之上,我想使其中一個條形圖透明。我試過這個:條形圖透明度不起作用

[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: '' 

回答

2

這是因爲B2沒有任何孩子,讓ch是(至少在R2015B)空。

您可以FaceAlpha財產直接使用例如

B2 = bar(xout,n/sum(n),'r','facea',.4); 

,而不是找它的孩子改變。

+0

當我嘗試這個時,我得到這個錯誤:'沒有bar class上的facea屬性。' – cosmictypist

+0

我使用R2015a – cosmictypist

+0

哦拍攝。那麼FaceAlpha呢? –