Demetri Pananos
Demetri Pananos

Reputation: 7404

How do I increase the spacing between subplots with subplot2grid?

I use subplot2grid to make a subplot like the following:

enter image description here

In order to make the ticks sufficiently large for publication, I need to increase the vertical and horizontal spacing between axes.

Normally, I would use something like subplot_adjust(hspace = 0.5), but that doesn't seem to work with subplot2grid.

Could anyone please recommend a solution?

Here is the code I use to plot things and create the axes:

import matplotlib.pyplot as plt

ax1  = plt.subplot2grid((2,2),(0,0), colspan = 2)
ax2  = plt.subplot2grid((2,2),(1,0), colspan = 1)
ax3  = plt.subplot2grid((2,2),(1,1), colspan = 1)

df.plot( ax = ax1)
plt.show()

Upvotes: 9

Views: 8030

Answers (2)

Dane
Dane

Reputation: 1

You can add the following line:

plt.subplots_adjust(hspace=0.8)

under this one:

ax3 =plt.subplot2grid((2,2),(1,1), colspan = 1)

You can play with all sorts of parameters this way.

Upvotes: -1

Demetri Pananos
Demetri Pananos

Reputation: 7404

I've found the solution here

The code is as follows:

AX = gridspec.GridSpec(2,2)
AX.update(wspace = 0.5, hspace = 0.5)
ax1  = plt.subplot(AX[0,:])
ax2 = plt.subplot(AX[1,0])
ax3 = plt.subplot(AX[1,1])

Which produces the same subplots with increased horizontal and vertical spacing.

Upvotes: 5

Related Questions