Add padding to the top and bottom of a pyplot

matplotlib, padding, python

Solution

You might want to take a look at the tight_layout guide, which describes how to do this sort of thing automagically. This was only introduced recently (in version 1.1) though.

Alternatively, you get a lot more control if you use the add_axes command instead of subplot(), which allows you to set the relative position and size of each graph.

Problem

I am generating a pyplot using the following code: ``` plotCount = 1 for key in resultsDictionary: count = 1 p1 = plt.subplot(5,1,plotCount) plotCount+=1 for item in resultsDictionary[key]: print count , item , key plt.plot(item, count, marker='o') count+=1 ``` The generated plot has the top and bottom results 'squashed' on the graph. How can I add some kind of padding to the top of the graph and size of the graph (or is it possible to set the exact size of the graph (I know the min/max values). If anyone can point me in the right direction I'd appreciate it.

Original source