title: Order area plots by their visible area, to maximize displayed information
body: <p>I'm trying to plot a series of area plots in front of each others (not stacked). The problem is they sometimes hide each other. Take a look at this example:</p>
  <pre><code>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
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Rc4Wl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rc4Wl.png" alt="enter image description here" /></a></p>
  <p>I tried to sort surfaces by their area to get a better result:</p>
  <pre><code>%% 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), :), 'facecolor', C(order(i), :))
  end
  </code></pre>
  <p><a href="https://i.stack.imgur.com/q1ZKU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1ZKU.png" alt="enter image description here" /></a></p>
  <p>But the result is not satisfactory yet. I think the objective here is <em>to maximize the area of least visible surface</em>.</p>
  <pre><code>%% order surfaces by VISIBLE area
  betterOrderIMO = [3 1 4 2 ];
  h(3) = figure; hold on
  for i=1:n
      area(t, y(betterOrderIMO(i), :), 'facecolor', 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)&amp; I(:, :, 2)==C(j, 2)&amp;I(:, :, 3)==C(j, 3)));
      end
  end
  min(N, [], 2)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/bRDV8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bRDV8.png" alt="enter image description here" /></a></p>
  <blockquote>
  <p>ans = -&gt; No. of pixels of the least visible surface</p>
  <pre><code>    2363 -&gt; not ordered
      3034 -&gt; ordered by area
      4146 -&gt; ordered manually
  </code></pre>
  </blockquote>
  <p>I can run an optimization (e.g. <code>ga</code>), but that seems overkill.<br />
  So are there any other options to get the bast order of a series of area plots, that maximizes the area of least visible plot?</p>