按可见区域对区域图进行排序,以最大程度地显示信息

问题描述

我正在尝试在彼此前面绘制一系列面积图(未堆叠)。问题在于它们有时会彼此隐藏。看一下这个例子:

clc; close all; clear variables;
%% generate some data
p = {[0 1 0 1.1];
    [0 1 0 1];
    [0 1 0 0.2];
    [0.1 0.9 0 1.1]};
t = linspace(0,2*pi);
y = cell2mat(cellfun(@(p) abs(p(1) + p(2)*sin(p(3)+p(4)*t)),p,'UniformOutput',0));

%% area plots without any order
n = size(p,1);
C = lines(n);
h(1) = figure; hold on
for i=1:n
    area(t,y(i,:),'facecolor',C(i,:))
end

enter image description here

我试图按面积对表面进行排序,以获得更好的结果:

%% order surfaces by their area
integral = sum(y,2);
[~,order] = sort(integral,'descend');
h(2) = figure; hold on
for i=1:n
    area(t,y(order(i),C(order(i),:))
end

enter image description here

但是结果还不令人满意。我认为这里的目标是最大程度地减少可见表面的面积

%% order surfaces by VISIBLE area
betterOrderIMO = [3 1 4 2 ];
h(3) = figure; hold on
for i=1:n
    area(t,y(betterOrderIMO(i),C(betterOrderIMO(i),:))
end

%% test visible area
N = zeros(3,n);
C = floor(C*256);
for i=1:3
    f = getframe(h(i));
    I = (f.cdata);
    for j=1:n
        N(i,j) = sum(sum(I(:,:,1)==C(j,1)& I(:,2)==C(j,2)&I(:,3)==C(j,3)));
    end
end
min(N,[],2)

enter image description here

ans =->最不可见表面的像素数

    2363 -> not ordered
    3034 -> ordered by area
    4146 -> ordered manually

我可以进行优化(例如ga),但这似乎有些过分。
那么,是否有其他选择来获得一系列区域图的野兽顺序,从而使可见度最小的区域最大化?

解决方法

您的问题似乎是根据您的评论同时显示很多信号/功能。您如何使用3D透视图?

%% generate some data
p = {[0 1 0 1.1];
    [0 1 0 1];
    [0 1 0 0.2];
    [0.1 0.9 0 1.1]};
t = linspace(0,2*pi);
y = cell2mat(cellfun(@(p) abs(p(1) + p(2)*sin(p(3)+p(4)*t)),p,'UniformOutput',0));

%% area plots without any order
n = size(p,1);
C = lines(n);
h(1) = figure; hold on
for i=1:n
    patch( i*ones([1 numel(t)+2]),[t(1) t t(end)],[0 y(i,:) 0],C(i,:) );
end
view(3);
grid on;

Three-dimensional view,filled faces.

您可能希望将 x 轴上的刻度标签替换为更有意义的内容。

另一个选择是:

%% generate some data
p = {[0 1 0 1.1];
    [0 1 0 1];
    [0 1 0 0.2];
    [0.1 0.9 0 1.1]};
t = linspace(0,1);
C = lines(n);
h(1) = figure;
h_patch=waterfall( [t(1) t t(end)],1:n,[zeros([n 1]) y zeros([n 1])],(1:n).'.*ones([n numel(t)+2]) );
colormap(C);
set(h_patch,'FaceColor','none');
set(h_patch,'LineWidth',2);
view(-15,75);

Three-dimensional view,transparent faces.