f = plt.figure(figsize=(20, 10))
gs = gridspec.GridSpec(4, 2)
ax0 = plt.subplot(gs[0, 0])
ax1 = plt.subplot(gs[0, 1])
ax2 = plt.subplot(gs[1, 1])
ax3 = plt.subplot(gs[1, 0])
ax4 = plt.subplot(gs[2, 0])
ax5 = plt.subplot(gs[2, 1])
ax6 = plt.subplot(gs[3, 1])
ax7 = plt.subplot(gs[3, 0])
axes = [ax0, ax1, ax2, ax3, ax4, ax5, ax6, ax7]
axes_twin = [ax.twinx() for ax in axes]
for param_set in results.keys():
for i, (ax, ax_twin) in enumerate(zip(axes, axes_twin)):
t_test_plot = np.random.uniform(low=0.0, high=1.0, size=100)
i_test_plot = np.random.uniform(low=0.0, high=1000, size=100)
d_test_plot = np.random.uniform(low=0.0, high=10, size=100)
ax.plot(t_test_plot, i_test_plot, color='lightgrey')
temp = ax_twin.plot(t_test_plot, d_test_plot, label=keys)
The above code will generate a plot that looks like this:
I searched on stackoverflow, and got this code to do figure legend:
handles, labels = ax_twin.get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center')
But this had no effect.
Here's what I want. I took a screenshot of my plot, and generated a legend from a different plot and photoshopped them:
How can I do this?