八度:使用颜色混合创建两个直方图

Pau*_*ers 5 plot histogram octave

我在Octave中创建了一个直方图.

    hold on;
    hist(normalData(:, column), 10, 1, "facecolor", "g");
    hist(anomalousData(:, column), 10, 1, "facecolor", "r");
    hold off;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

正如您所看到的那样,重叠并且红色数据掩盖了一些绿色数据.有没有解决的办法?也许是通过在重叠部分混合颜色?

use*_*813 6

你的问题还有很长的路要走.不幸的是,透明度"facealpha"的绘图属性不适用于hist()函数.

下面的代码显示了我的工作.默认的图形工具包可能是fltk,因此将其更改为gnuplot.

clear all

graphics_toolkit("gnuplot")

A = randn(1000,1);
B = randn(1000,1)+2;
Run Code Online (Sandbox Code Playgroud)

仍然使用hist来计算分布

[y1 x1] = hist(A,10);
[y2 x2] = hist(B,10);
Run Code Online (Sandbox Code Playgroud)

现在我们将把hist数据转换成一种允许透明度的绘图格式.

[ys1 xs1] = stairs(y1, x1);
[ys2 xs2] = stairs(y2, x2);

xs1 = [xs1(1); xs1; xs1(end)];  xs2 = [xs2(1); xs2; xs2(end)];
ys1 = [0; ys1; 0];  ys2 = [0; ys2; 0];
Run Code Online (Sandbox Code Playgroud)

使用填充函数绘制数据

clf
hold on; 
h1=fill(xs1,ys1,"red");
h2=fill(xs2,ys2,"green");
Run Code Online (Sandbox Code Playgroud)

将透明度更改为所需级别.

set(h1,'facealpha',0.5);
set(h2,'facealpha',0.5);
hold off;
Run Code Online (Sandbox Code Playgroud)

如果我有更多声望,我会发布一张图片.