user1462442
user1462442

Reputation: 8202

Matplotlib graph placement

I need a little help with formatting. How do I change the distance between the second and third graph

   from matplotlib.font_manager import FontProperties
   import matplotlib.pyplot as plt


   fig  = plt.figure(1)
   graph1 = fig.add_subplot(3,1,1)
   graph2 = fig.add_subplot(3,1,2)
   norm =  fig.add_subplot(3,1,3)

   graph1.set_title(TITLE + '\nscaling factor: ' +str(round(rescale,3)))
   norm.set_title('Circle and Oval Height Difference')
   norm.set_xlabel(XLABEL +'(Degrees)')
   norm.legend(bbox_to_anchor=(1.13,1), prop={'size':8})
   plt.ylabel('Heights (nm)')


   graph1.legend(bbox_to_anchor=(1.13,1),prop={'size':8})
   graph2.legend(bbox_to_anchor=(1.13,1),prop={'size':8})
   fontP = FontProperties()
   fontP.set_size('small')

enter image description here

Upvotes: 1

Views: 212

Answers (2)

Steve
Steve

Reputation: 8293

The quick answer is fig.subplots_adjust, setting hspace to a larger value. Unfortunately this also inserts some space between the top two graphs, but this may be good anyways, depending on what you want. As Joe says, I often remove the x-axes if they are the same.

If you want to have uneven spacing, i.e. more spacing between 2 and 3 than between 1 and 2, you need to explicitly instantiate the Axes at a particular position using fig.add_axes.

Upvotes: 4

heltonbiker
heltonbiker

Reputation: 27615

Use

plt.subplots_adjust(hspace=desiredspace)

I'm pretty sure, the way matplotlib is, there could be some more ways to do that, but it solves my problem, even having to figure out by hand the best value.

Hope this helps!

Upvotes: 2

Related Questions