0

I am pretty new to python, and I am plotting two imshow objects into a figure, one below the other. However, I am not able to change the horizontal distance between the two objects, i.e. they are too far apart.

As suggested in Improve subplot size/spacing with many subplots in matplotlib, I have tried using plt.tight_layout() and plt.subplots_adjust, but it didn't affect the plot at all.

This is how I created the plot (I left out the parts where I define the arrays to be plotted and the properties of the imshow plot):

fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.imshow(help_vector, cmap=cmap, norm=norm)
ax2 = fig.add_subplot(212)
ax2.imshow(plot_vector, cmap=cmap, norm=norm)

I dont't know if this is important, but both subplots have a title, the whole figure has a title, and the second subplot has a 'legend' next to it which I created by using the follwing code:

patches = [mpatches.Patch(color='lime', label = 'No relevant error'), mpatches.Patch(color='yellow',label='Medium error'), mpatches.Patch(color='orange',label='Large error'), mpatches.Patch(color='red',
    label='Unacceptable')]
    plt.legend(handles=patches, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0)

When storing the image with savefig, I added the argument bbox_inches='tight'.

Image of the plot

Any kind of help is very much appreciated!

Edit: Added an image of the plot.

Wolfie55
  • 1
  • 1

1 Answers1

0

As @ImportanceOfBeingErnest pointed out, the solution was to use the top and bottom parameters of subplots_adjust(). In my case, fig.subplots_adjust(top=0.7,bottom=0.3) was what I needed.

Wolfie55
  • 1
  • 1