title: Choosing an attractive linear scale for a graph's Y Axis
body: <p>I'm writing a bit of code to display a bar (or line) graph in our software.  Everything's going fine.  The thing that's got me stumped is labeling the Y axis.</p>
  
  <p>The caller can tell me how finely they want the Y scale labeled, but I seem to be stuck on exactly what to label them in an "attractive" kind of way.  I can't describe "attractive", and probably neither can you, but we know it when we see it, right?</p>
  
  <p>So if the data points are:</p>
  
  <pre><code>   15, 234, 140, 65, 90
  </code></pre>
  
  <p>And the user asks for 10 labels on the Y axis, a little bit of finagling with paper and pencil comes up with:</p>
  
  <pre><code>  0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250
  </code></pre>
  
  <p>So there's 10 there (not including 0), the last one extends just beyond the highest value (234 &lt; 250), and it's a "nice" increment of 25 each.  If they asked for 8 labels, an increment of 30 would have looked nice:</p>
  
  <pre><code>  0, 30, 60, 90, 120, 150, 180, 210, 240
  </code></pre>
  
  <p>Nine would have been tricky.  Maybe just have used either 8 or 10 and call it close enough would be okay.  And what to do when some of the points are negative?</p>
  
  <p>I can see Excel tackles this problem nicely.  </p>
  
  <p>Does anyone know a general-purpose algorithm (even some brute force is okay) for solving this?  I don't have to do it quickly, but it should look nice.</p>