0

A follow on to the question How to remove the space between subplots in matplotlib.pyplot?, After multiple attemps at creating subplots with no space between them I have discovered that all solutions do not apply to polar projections. Both of the code samples below will work correctly if the polar projections is removed (that is show subplots side by side with no white space) but when the polar is added, white space shows up between the columns.

Sample 1

m,n,_ = ws.shape
fig,axs = plt.subplots(m,n,
                       subplot_kw=dict(projection='polar'),
                       gridspec_kw={'wspace':0,'hspace':0})

for i in range(m):
    for j in range(n):
        ax = axs[i][j] # current axes
        w = ws[i][j]   # current weight vector
        a = numpy.linspace(0,2*numpy.pi,len(w),endpoint=False)
        a = numpy.concatenate((a,[a[0]]))
        w = numpy.concatenate((w,[w[0]]))

        ax.fill(a,w,alpha=1.0)
        ax.set_thetagrids([])
        ax.set_yticklabels([])
        ax.set_rticks([])
plt.show()  

Sample 2

m,n,_ = ws.shape
fig = plt.figure()
gs = gridspec.GridSpec(m,n,width_ratios=[1,1,1,1,1,1],wspace=0.0,hspace=0.0)
for i in range(m):
    for j in range(n):
        ax = plt.subplot(gs[i,j],projection='polar')

        w = ws[i][j]   # current weight vector
        a = numpy.linspace(0,2*numpy.pi,len(w),endpoint=False)
        a = numpy.concatenate((a,[a[0]]))
        w = numpy.concatenate((w,[w[0]]))

        ax.fill(a,w,alpha=1.0)
        ax.set_thetagrids([])
        ax.set_yticklabels([])
        ax.set_rticks([])            
plt.show()

I have also toyed with changes parameters in matplotlibrc as suggested in other answers. Has anybody come up with a solution to this?

1 Answers1

2

Similarly to the answer you linked, doing a polar plot automatically sets the axes aspect to "equal" to get a nice looking circle (instead of an ellipse). That means that if you want your axes to touch, you also need to properly adjust the figure dimensions so it has the correct width/height ratio.

m,n = 7,3
fig,axs = plt.subplots(m,n,
                       subplot_kw=dict(projection='polar'),
                       gridspec_kw={'wspace':0,'hspace':0,
                                    'top':1., 'bottom':0., 'left':0., 'right':1.},
                       figsize=(n,m))  # <- adjust figsize but keep ratio n/m
for ax in axs.flat:
    ax.set_thetagrids([])
    ax.set_yticklabels([])
    ax.set_rticks([])
plt.show()

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75