I am trying to display multiple legends within multiple subplots. Currently, I am able to create figures with subplots and display multiple legends within one plot but can't combine the two. They seem to default to the last subplot.
This is the code I found that got me the closest:
import matplotlib.pyplot as plt
import numpy as np
f, axs = plt.subplots(2)
l1, = axs[0].plot([0, 1], [1, 0], label="line1")
h1 = [l1]
l2, = axs[0].plot([0, 1], [0, 1], "--", label="line2")
h2 = [l2]
lab1 = [h.get_label() for h in h1]
lab2 = [h.get_label() for h in h2]
leg1 = plt.legend(h1, lab1, loc=1)
leg2 = plt.legend(h2, lab2, loc=4)
plt.gca().add_artist(leg1)
plt.show()
But can't control the location of: plt.gca().add_artist(leg1)
Hopefully there's a better way to do this.