Spurious borders when setting figure size


The script pasted below plots a square array. The (very small) output
PDF is attached to this posting. For reasons I do not understand,
there's a fine additional border immediately at the top and bottom of
the array.

If the commented-out line of code is removed, the strange border

Now you will ask, why do I create the figure in this way and don't
simply use the commented-out line? The answer is that this script is a
simplified version of the function "map" from
There, we need to create a figure also when pyplot has not been

If we would import matplotlib.pyplot, the user of our package could not
freely choose the matplotlib backend himself.


test.pdf (5.22 KB)



import numpy as np
from matplotlib import pyplot
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg

data = np.random.random((11, 11))

fig = Figure()
ax = fig.add_subplot(1, 1, 1, aspect='equal', adjustable='datalim')

# Uncommenting the following line makes it work.
# fig, ax = pyplot.subplots()

image = ax.imshow(data, extent=(-49.5, 49.5, -49.5, 49.5),
fig.canvas = FigureCanvasAgg(fig)
fig.set_size_inches(5, 5)