Show Legend (legend)

Source: Internet
Author: User

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 ()





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.