Jim Jim - 1 year ago 296
Python Question

How to remove white space at the bottom of matplotlib graph?

I looked over the matplotlib user guide and cant seem to find a way to remove the white space that is generated at the bottom of my graph.

fig = plt.figure(1,figsize=(5,10))
axis = fig.add_subplot(211, autoscale_on=False,xlim=(1,10),ylim=(0,1))

Are the configurations I am using on the graph. I tried using frameon=False, but didnt notice it do anything. I would like the graph to take up the entire size of the output image.

Here is the photo:
Notice that half the graph is half white space at the bottom.

I want to remove all this white space. Both the answers provided do not do this... am I missing something else?

Answer Source

You're creating space for a second plot and not using it. The line

axis = fig.add_subplot(211, autoscale_on=False,xlim=(1,10),ylim=(0,1))

adds a subplot to the figure, but the 211 means "two plots high by one plot wide, position 1". You could add a second plot below your current one with another subplot call, passing `212' (position 2).

To create a single subplot and fix your issue, change your add_subplot call to:

axis = fig.add_subplot(111, autoscale_on=False,xlim=(1,10),ylim=(0,1))

The 111 meaning one by one plots, first position.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download