【问题标题】:bar plot transparency not working条形图透明度不起作用
【发布时间】:2016-04-26 14:58:43
【问题描述】:

我正在绘制两个相互重叠的频率条形图,我想让其中一个条形图透明。我试过这个:

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

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

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

    您可以使用示例直接更改FaceAlpha 属性

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

    而不是寻找它的孩子。

    【讨论】:

    • 当我尝试这个时,我得到这个错误:There is no facea property on the Bar class.
    • 哦,拍摄。 FaceAlpha呢?
    • mhh 我真的很困惑。您能否将此命令的输出添加到您的问题中:get(B2)
    • 我也是。我已将get(B2) 的输出添加到我原来的问题中
    • 用您的数据创建一个histogram 怎么样?然后你应该可以修改FaceAlpha属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多