title: Tabular text in matplotlib text box
body: <p>I'm trying to display some statistics in a matplotlib text box in a tabular format.</p>
  
  <p>Getting the text box to display works fine, and tabularizing data outside a plot with print statements using string formatting align operands ('>', '&lt;') works fine, but once I wrap the formatted strings in ax.text(), the alignment seems to get ignored.</p>
  
  <p>For example:</p>
  
  <pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt
  import numpy as np
  
  def plot_histo(data, stats):
      fig, ax = plt.subplots()
      n, bins, patches = plt.hist(data, bins=16, alpha=0.5)
      props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
      ax.text(0.8, 0.85, stats, transform=ax.transAxes, bbox=props)
      plt.show()
  
  data = np.random.normal(size=100)
  stats = '\n'.join([
          '{:&lt;8}{:&gt;4}'.format('n:', len(data)),
          '{:&lt;8}{:&gt;4.2f}'.format('Mean:', np.mean(data)),
          '{:&lt;8}{:&gt;4.2f}'.format('SD:', np.std(data)),
  ])
  plot_histo(data, stats)
  </code></pre>
  
  <p>plots like</p>
  
  <p><a href="https://i.stack.imgur.com/yCDmV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCDmV.png" alt="Histogram"></a></p>
  
  <p>But, using a print statement:</p>
  
  <pre class="lang-py prettyprint-override"><code>print(stats)
  </code></pre>
  
  <p>outputs the desired, aligned, tabular format.</p>
  
  <pre><code>n:       100
  Mean:   0.01
  SD:     0.95
  </code></pre>
  
  <p>Any ideas on how to get the tabular formatting in a text box? Using a monospaced font is undesirable for the end application.</p>