title: Matplotlib: Center text in its bbox
body: <p>I have to plot some data and some vertical lines to delimit interesting intervals and then I would like to add some labels to that using <code>text</code>. I can not entirely avoid the labels overlapping with the data or the vertical lines, so I decided to put a <code>bbox</code> around the text to keep it readable. My problem is that I am not able to align it centrally within this box and this is clearly visible and quite annoying in my opinion.</p>
  
  <p>I'm doing something like this:</p>
  
  <pre><code>import numpy
  import matplotlib
  import matplotlib.pyplot as plt
  
  fig=plt.figure()
  plot=fig.add_subplot(111)
  x=numpy.linspace(1,10,50)
  y=numpy.random.random(50)
  plot.plot(x,y)
  plot.text(4.5,.5,'TEST TEST',\
            bbox={'facecolor':'white','alpha':1,'edgecolor':'none','pad':1})
  plot.axvline(5,color='k',linestyle='solid')
  plt.show()
  </code></pre>
  
  <p>Which creates the following plot:
  <a href="https://i.stack.imgur.com/B2ASO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B2ASO.png" alt="enter image description here"></a></p>
  
  <p>It is quite apparent, that the text is not centered in its <code>bbox</code>. How can I change this? I've spent quite some time on Google but I could not find anything.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks for the suggestions so far.</p>
  
  <p><a href="https://github.com/matplotlib/matplotlib/issues/2527" rel="noreferrer">This</a> suggests that what I see is actually desired behavior. Apparently the <code>bbox</code> in new versions of <code>matplotlib</code> is chosen taking into account the possible maximum descent of the text it contains (the descent of 'g').</p>
  
  <p>When a 'g' appears in the text, this does indeed look good:
  <a href="https://i.stack.imgur.com/dy7oE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dy7oE.png" alt="enter image description here"></a>
  Unfortunately in my case there is no 'g' or anything with a similar descent. Does anyone have any further ideas?</p>