title: How does matplotlib calculate the min / max axis values? Or how to automatically add the matplotlib margin when setting the limits
body: <p>When we plot a curve, matplotlib automatically adds some offset to the minimum and maximum points. How does matplotlib calculate this 'offset'?</p>
  <p>E.g.</p>
  <pre><code>plt.plot(range(0,10))
  plt.ylim()
  </code></pre>
  <p>gives the <code>y</code> limits <code>(-0.45, 9.45)</code>.
  while</p>
  <pre><code>plt.plot(np.array(range(1,10))/100)
  plt.ylim()
  </code></pre>
  <p>gives the <code>y</code> limits <code>(0.006, 0.094)</code>.
  Not surprisingly, when I set axis</p>
  <pre><code>plt.plot(range(0,10))
  plt.ylim(0,9)
  plt.ylim()
  </code></pre>
  <p>I get <code>(0.0, 9.0)</code>.</p>
  <p>Often I want to set limits, but still want some margin on the limit, e.g. when the limit is on a line, the line should be nicely displayed.</p>
  <p>Of course I can add some fraction when setting the <code>y</code> limit but this always requires some tweaking. I am wondering if there is a smarter way to do it.</p>