更好的解决方案是
fig.legend(handles, labels, loc='', ...)
这会将图例而不是子图添加到图中。
适应你的例子,它会是这样的
fig = plt.figure()
matplotlib.rc('xtick', labelsize=8)
matplotlib.rc('ytick', labelsize=8)
handles = []
for line in a[1:]:
ax = fig.add_subplot(subcol,subrow,counter)
l1 = ax.plot(x,line[3:7],marker='o', color='r', label = 'oral')
l2 = ax.plot(x,line[7:],marker='o', color='b',label = 'physa')
if not handles:
handles = [l1, l2]
ax.set_title(line[1],fontsize = 10)
counter+=1
fig.legend(handles, ['oral', 'physa'], bbox_to_anchor=(2, 0),loc = 'lower right')
plt.subplots_adjust(left=0.07, right=0.93, wspace=0.25, hspace=0.35)
plt.suptitle('Kegg hedgehog',size=16)
plt.show()