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'
.
Any kind of help is very much appreciated!
Edit: Added an image of the plot.