The most of contents borrowed from the book 『Python Data Science Handbook: Essential Tools for Working with Data, Jake VanderPlas, O'REILLY, 2017』. I have just added somewhat object-oriented or matlab style codes.

There are 3 different ways to set labels for multiple lines

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
In [2]:
x = np.linspace(0, 10, 1000)
In [3]:
# 1. inside plot()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

ax1.plot(x, np.sin(x), '-g', label='sin(X)')
ax1.plot(x, np.cos(x), ':b', label='cos(X)')
ax1.axis('equal')
ax1.legend()
#ax1.legend('sin(x), cos(x)')
Out[3]:
<matplotlib.legend.Legend at 0x1da33303848>
In [4]:
# 2. using line ojbects
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

line1, = ax1.plot(x, np.sin(x), '-g')
line2, = ax1.plot(x, np.cos(x), ':b')
ax1.axis('equal')

line1.set_label('sin(x)')
line2.set_label('cos(x)')
ax1.legend()
Out[4]:
<matplotlib.legend.Legend at 0x1da333cd988>
In [5]:
# 3. using legend()
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

line1, = ax1.plot(x, np.sin(x), '-g')
line2, = ax1.plot(x, np.cos(x), ':b')
ax1.axis('equal')

#legend(handles, labels)
ax1.legend((line1, line2), ('sin(X)', 'cos(X)'))
Out[5]:
<matplotlib.legend.Legend at 0x1da3344df88>
In [ ]: