Draw two legends in one figure using Python & Matplotlib.pyplot

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
plt.figure(figsize=(4,3))

l1, = plt.plot([0,1],[1,0],label="l1")
l2, = plt.plot([0,1],[1.1,0],label="l2")
l3, = plt.plot([0,1],[1.2,0],label="l3")
h1 = [l1, l2, l3]
l4, = plt.plot([0,1],[0,1],"--",label="l4")
l5, = plt.plot([0,1],[0,1.1],"--",label="l5")
h2 = [l4, l5]

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) # 最後の legend しか自動認識してくれない
plt.show()