【问题标题】:Plotting multiple normalized histograms along third axis沿第三轴绘制多个归一化直方图
【发布时间】:2017-01-01 23:39:58
【问题描述】:

我想在一个图中绘制多个直方图,直方图沿第三个轴分开。

例如,假设我想绘制以下两个直方图(实际上,我想同时绘制 10 个直方图):

它们由以下代码生成:

histogram(points_inside1,100,'Normalization','pdf')

histogram(points_inside2,100,'Normalization','pdf')

其中 'points_inside1' 和 'points_inside2' 是具有 10^5 个条目的数组。

我无法让bar3 工作(我认为它不能将标准化直方图作为输入)。

谢谢。

【问题讨论】:

    标签: matlab histogram matlab-figure


    【解决方案1】:

    要做到这一点,你需要先通过histcounts获取直方图数据,然后用bar3绘制:

    % some data:
    p1 = randn(1000,1)+2;
    p2 = randn(1000,1);
    % don't use too many bins:
    bins = 10;
    % get the histogram data:
    [N1] = histcounts(p1,bins,'Normalization','pdf');
    [N2] = histcounts(p2,bins,'Normalization','pdf');
    % plot it:
    bar3([N1.' N2.']);
    

    但是,由于 X 轴未在所有直方图之间对齐,您可能仍然会遇到问题,因此您可以将组合直方图的 edges 用于所有其他直方图:

    % get the histogram data:
    [~,edges] = histcounts([p1;p2],bins,'Normalization','pdf');
    [N1] = histcounts(p1,edges,'Normalization','pdf');
    [N2] = histcounts(p2,edges,'Normalization','pdf');
    % compute the correct X-tick values:
    X = movmean(edges.',2);
    % plot it:
    b = bar3(X(2:end),[N1.' N2.']);
    

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 2017-08-21
      • 2017-10-24
      • 1970-01-01
      • 2016-07-02
      • 2014-06-19
      相关资源
      最近更新 更多