I'm using matplotlib.offsetbox to draw a text box as seen below:
The text box clearly shows too much space at the bottom and not enough at the top.
Why does this happen and how can I fix it?
(Add: I've opened a bug report over at matplotlib
's tracker)
MWE
import matplotlib.pyplot as plt
import matplotlib.offsetbox as offsetbox
import matplotlib.gridspec as gridspec
import random
def scatter_plot(x, y):
ax = plt.subplot(gs[0:2, 0:2])
# Add text box
text1 = '$N = {}$\n'.format(0)
text2 = '$a = {} \pm {}$\n'.format(0.01, 0.01)
text3 = '$log(b) = {} \pm {}$\n'.format(1.2, 0.3)
text4 = '$C_{{(aaa)}} = {} \pm {}$\n'.format(0.2, 0.05)
text5 = '$D_o = {} \pm {}$\n'.format(10.6, 0.7)
text6 = '$E_{{\odot}} = {} \pm {}$\n'.format(100., 200.)
text7 = '$F_{{fff}} = {} \pm {}$'.format(0.5, 0.3)
text = text1 + text2 + text3 + text4 + text5 + text6 + text7
ob = offsetbox.AnchoredText(text, loc=1, prop=dict(size=12))
ob.patch.set(boxstyle='square,pad=0.2', alpha=0.85)
ax.add_artist(ob)
plt.scatter(x, y)
# Generate random data.
x = [random.random() for i in xrange(100)]
y = [random.random() for i in xrange(100)]
# Define size of output figure.
fig = plt.figure(figsize=(30, 25)) # create the top-level container
gs = gridspec.GridSpec(10, 12) # create a GridSpec object
# Create plot.
scatter_plot(x, y)
# Save plot to file.
fig.tight_layout()
plt.savefig('out.png', dpi=150)