0

I have a code that looks like this:

import matplotlib.pyplot as plt

x1 = [1, 2, 3]
y1 = [1, 2, 3]
x2 = [1, 2, 3]
y2 = [53, 2, 3]

fig = plt.figure()
ax = fig.add_subplot(111)

ax.semilogx(x1, y1, marker='o', label='Phase Envelope')
ax.semilogx(x2, y2, marker=',', label='Isotherm, 200 C')

plt.show()

I want to add legend to each line, but for some reason label = '...' argument does not work. I thought this was the code that adds legend. What should I do?

Eric Kim
  • 2,493
  • 6
  • 33
  • 69
  • 1
    Add `plt.legend()` to your code. – Mr. T Feb 12 '18 at 23:35
  • Matplotlib is constantly trying to improve [its documentation](https://matplotlib.org/2.1.2/tutorials/index.html#introductory). Hence it would be interesting to know at which point it would have helped you to read about adding `plt.legend()` to create a legend, such that you would not have needed to ask this question. – ImportanceOfBeingErnest Feb 13 '18 at 00:06

0 Answers0