python - Matplotlib global legend for lots of subplots -
i have problem figuring out how force matplotlib add legend want.
i generate 2 paged plot following script:
n = 1 trn = true in diff.keys(): plt.subplot(8, 4, n) plt.xlim([0, rounds + 1]) plt.locator_params(axis='y', nbins=5) if peptide_kd[i] == 1e-2: plt.plot(x_cord, [x[0] x in diff[i]], 'ro--', label='asd') plt.plot(x_cord, [x[1] x in diff[i]], 'rv--', label='bsd') else: plt.plot(x_cord, [x[0] x in diff[i]], 'bo--', label='asd') plt.plot(x_cord, [x[1] x in diff[i]], 'bv--', label='csd') plt.title(i) n += 1 if n == 33 , trn: n = 1 trn = false plt.suptitle('ligand energies') plt.locator_params(axis='y', nbins=5) plt.subplots_adjust(hspace=0.35) plt.show() plt.legend(bbox_to_anchor=(-0.05, 1), loc=1) plt.locator_params(axis='y', nbins=5) plt.subplots_adjust(hspace=0.35) plt.show()
however place legend @ left side of first subplot, or right side of last subplot in first line.
i can if line == 0
bla bla, problem can see in plots attached example last plot contains blue data, hence blue legend show. place full legend (red , blue) same place. dont know blue , red plot placed beforehand.
is possible?
try using figure legend let create legend any of lines plotted in figure , position relative figure.
Comments
Post a Comment