如何将每个观测值的概率分布绘制为彩色图?

时间:2019-06-06 07:01:18

标签: matlab matlab-figure

让我们说以下11个值:

>> values=[100:10:200]

values =

   100   110   120   130   140   150   160   170   180   190   200

11个值中的每个都是随机分布,每个值的概率可能在0到300之间。

例如,从概率分布dist中获取第一个值100,如下所示:

>> dist=[0 0.1;50 0.3; 90 0.3; 150 0.2 ;160 0.1]

dist =

         0    0.1000
   50.0000    0.3000
   90.0000    0.3000
  150.0000    0.2000
  160.0000    0.1000

这意味着值100可能以0.1的概率取值为0,以0.3的概率取值为50,依此类推...

现在,在x轴上绘制一个简单的索引(1-11)图,并在y轴(0-300)上绘制可能发生的值范围,如下所示:

plot(1:11,values);ylim([0 300])

结果图如下:

enter image description here

让我们说我想用蓝色阴影沿Y轴绘制每个值的概率。较高的蓝色表示较高的值。

在我的示例中,有5个蓝色点,代表value = 100。在绘图上,点(1,0),(1,50),(1,90),(1,150),(1,160)将是一个填充的蓝色圆圈。点(1,0)应该比点(1,50)具有更亮的蓝色阴影,因为它出现的可能性较小。 Point(1,50)和point(1,90)应该具有相同的蓝色阴影,因为它们具有相同的概率。

我的想法在经过MSPAINT编辑的图片中表示如下:

enter image description here

如何在Matlab中生成以上所需的图?

1 个答案:

答案 0 :(得分:1)

scatter函数和creating custom colormaps有一些了解之后,这是一种简单明了的方法:

% Distributions
dist{1} = [0 0.1; 50 0.3; 90 0.3; 150 0.2; 160 0.1];
dist{2} = [0 0.01; 100 0.7; 150 0.29];
dist{3} = [160 1.0];

figure(1);
hold on;
for ii = 1:numel(dist)

  % Number of distribution values
  n = size(dist{ii}, 1);

  % Scatter plot: 
  %   x = iterating index 
  %   y = distribution value
  %   c = probability value
  scatter(ii .* ones(n, 1), dist{ii}(:, 1), 151, dist{ii}(:, 2), 'filled', 'MarkerEdgeColor', 'k');

end
hold off;
xlim([0 4]);
ylim([-50 300]);

% Colormap dark blue -> light blue
cm = [(0:0.01:1).' (0:0.01:1).' ones(101, 1)]
colormap(cm);
colorbar();

我们得到以下输出:

Output

如您所见,对于具有附近概率值(0.10.3)的示例(第一列),很难使用所选的颜色图来区分颜色。不过,您会看到它正在运行(第二列和第三列)。因此,也许试一下颜色图以找到最能满足您需求的颜色图。

希望有帮助!

相关问题