|
From: Christoph G. <chr...@gr...> - 2013-10-18 12:34:57
|
Hello, 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 disappears. 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 http://git.kwant-project.org/kwant/tree/kwant/plotter.py?id=v1.0.0 There, we need to create a figure also when pyplot has not been imported. If we would import matplotlib.pyplot, the user of our package could not freely choose the matplotlib backend himself. Thanks, Christoph **************************************************************** 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), interpolation='none') fig.canvas = FigureCanvasAgg(fig) fig.set_size_inches(5, 5) fig.savefig('test.pdf') |