title: Perl PDL -> GnuPlot -> AutoScale => 95% WhiteSpace?
body: <p>3 XY datasets to plot:</p>
  
  <pre><code>A) Function plot XY
  B) Polynomial, shares X with function, Y is poly_eval(x)
  C) Polynomial_error;  X, Y=poly(x) - fct(x)
  Range X:  ]0.0 .. 1.0[  (full range 0-&gt;1 plus some extra, both sides
  Range Y:  ]0.0 .. 1.0[
  </code></pre>
  
  <p>Wanted: All 3, XY datasets to plot auto-scaled as if it were the ONLY dataset. 
  Expect: "Small", whitespace above/below <br>
  Error data spanning entire Y range, not ~0 range near Y=0</p>
  
  <p>Result: Y Range [-10 .. 10] <br>
  Error line is flat line in the middle of the graph with ~0 content. 
  In the entire 20 unit Y range, only [0 .. 1] has any data, so 95% is blank space. </p>
  
  <p>IDEAL "Auto" scaling: Support "standard deviation" scaling where a few "outlying" data points will be pushed off the graph to better show the bulk of the data.  </p>
  
  <p>Case in point: Error XY data. On the extreme ends, Y error values are gigantic compared to the average, some 14 sigmas out. The auto scaling squashes the 98% of data to within a pixel of zero. <br></p>
  
  <p>If I calculate the standard deviation and manually set yrange=>[$ylo, $yhi] to something like average +- 1 sigma, it looks informative. </p>
  
  <p>Is there any way to get REASONABLE-SCALE other than max/min or order of magnitude AUTOSCALE?</p>
  
  <pre><code>#!/usr/local/bin/perl -w
  
  use PDL::IO::Misc;
  use PDL::Graphics::Gnuplot;
  use PDL::Fit::Polynomial;
  use PDL::Core;
  use List::Util qw(max min);
  
  for($mi=0; $mi &lt; scalar @mxa; $mi++)  {
      @xara = @{$mxa[$mi]};  # @MXA =&gt; Array of @xara 
      @yara = @{$mya[$mi]};  # @MYA =&gt; Array of @yara 
      $px   = pdl(\@xara);  
      $py   = pdl(\@yara);
      if($mi &gt; 0)  {
          $pw-&gt;replot(with=&gt;"lines", linewidth=&gt;5, $px, $py);  # autoscale=&gt;'', 
          next;  
      }
      # Use autoscale=&gt;'' to "set [autoscale] all the axes at once" 
      $pw=gpwin("png", output=&gt;"$imgfn", size=&gt;[$pxres,$pyres,'px'],font=&gt;"=11");
      $pw-&gt;plot(title=&gt;"$title", xrange=&gt;[$xlo, $xhi], xlab=&gt;"$xlbl", 
          ylab=&gt;["$ylbl", "offset 1"], autoscale=&gt;'', 
          with=&gt;"lines", linewidth=&gt;5, linetype=&gt;2, linestyle=&gt;1, $px, $py);
  }  # End For MI
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8srkA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8srkA.png" alt="AutoScale with 5% Data"></a></p>