本文介绍了八度:使用颜色混合创建两个直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用八度创建另一个直方图.

I am creating one histogram on top of another in Octave.

    hold on;
    hist(normalData(:, column), 10, 1, "facecolor", "g");
    hist(anomalousData(:, column), 10, 1, "facecolor", "r");
    hold off;

如您所见,有重叠部分,红色数据遮盖了一些绿色数据.有没有解决的办法?也许是通过在重叠部分上混合颜色?

As you can see there is overlap and the red data obscures some of the green data. Is there a way around this? Perhaps by having the colors blend on the overlapping portions?

推荐答案

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

There is a long way around your problem. Unfortunately the plotting property for transparency "facealpha" does not work with the hist() function.

以下代码显示了我的解决方法.默认的图形工具包可能是fltk,因此请将其更改为gnuplot.

The code below shows my work around.The default graphics toolkit may be fltk, so change it to gnuplot.

clear all

graphics_toolkit("gnuplot")

A = randn(1000,1);
B = randn(1000,1)+2;

仍然使用hist来计算分布

Still use hist to calculate the distributions

[y1 x1] = hist(A,10);
[y2 x2] = hist(B,10);

现在,我们将把历史数据转换为可以透明的绘图格式.

Now we are going to convert the hist data into a format for plotting that will allow transparency.

[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];

使用填充功能绘制数据

clf
hold on;
h1=fill(xs1,ys1,"red");
h2=fill(xs2,ys2,"green");

将透明度更改为所需的水平.

Change the transparency to the desired level.

set(h1,'facealpha',0.5);
set(h2,'facealpha',0.5);
hold off;

如果我有更高的声誉,我会发布一张图片.

I'd post an image if I had more reputation.

这篇关于八度:使用颜色混合创建两个直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:47