Parameters:
LOC (Set the location where the legend is displayed)
' Best ' : 0, (only implemented for axes legends) (adaptive)
' upper right ' : 1,
' upper left ' : 2,
' Lower left ' : 3,
' lower right ' : 4,
' right ' : 5,
' center left ' : 6,
' Center right ' : 7,
' Lower center ': 8,
' Upper Center ': 9,
' Center ' : 10,
Ncol (Sets the number of columns so that the display is flattened, which is useful when the segments to be represented are particularly large)
How to use Pyplot
#!/usr/bin/python
#coding: utf-8
import numpy as NP
import Matplotlib.pyplot as plt
x = Np.arange (1, 11, 1)
# plt.plot (x, X * 2, label = "A")
# Plt.plot (x, X * 3, label = "Second")
# Plt.plot (x, X * 4, label = " Third ")
# # loc Set the position shown, 0 is Adaptive
# # Ncol Set the number of columns displayed
# plt.legend (loc = 0, Ncol = 2)
# You can also specify label
label = ["A", "Second", "third"]
plt.plot (x, X * 2)
plt.plot (x, X * 3)
Plt.plot (x, X * 4) plt.legend
(Lab El, loc = 0, Ncol = 2)
plt.show ()
Using an object-oriented approach
#!/usr/bin/python
#coding: utf-8
import numpy as NP
import Matplotlib.pyplot as plt
x = Np.arange (1, 11,
Be sure to pay attention to
# l, = Ax.plot (x, X * 2)
# L.set_label ("Demo")
# ax.legend (loc = 0)
# The second kind
# Ax.plot (x, X * 2 , label = "Demo")
# ax.legend (loc = 0)
# The Third Kind of
ax.plot (x, X * 2)
ax.legend ([' Demo '], loc = 0)
Plt.s How ()