text: # View more python tutorials on my Youtube and Youku channel!!!
  
  # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  # Youku video tutorial: http://i.youku.com/pythontutorial
  
  # 7 - legend
  """
  Please note, this script is for python3+.
  If you are using python2+, please modify it accordingly.
  Tutorial reference:
  http://www.scipy-lectures.org/intro/matplotlib/matplotlib.html
  """
  
  import matplotlib.pyplot as plt
  import numpy as np
  
  x = np.linspace(-3, 3, 50)
  y1 = 2*x + 1
  y2 = x**2
  
  plt.figure()
  # set x limits
  plt.xlim((-1, 2))
  plt.ylim((-2, 3))
  
  # set new sticks
  new_sticks = np.linspace(-1, 2, 5)
  plt.xticks(new_sticks)
  # set tick labels
  plt.yticks([-2, -1.8, -1, 1.22, 3],
             [r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])
  
  l1, = plt.plot(x, y1, label='linear line')
  l2, = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--', label='square line')
  
  plt.legend(loc='upper right')
  # plt.legend(handles=[l1, l2], labels=['up', 'down'],  loc='best')#loc='best'/0(docstring所示)表示在全图寻找最佳位置放置legend图例
  # the "," is very important in here l1, = plt... and l2, = plt... for this step#注意l1 l2后要加逗号
  #关于legend用法 loc函数的参数，位置选择问题，下面docstring所举
  """legend( handles=(line1, line2, line3),
             labels=('label1', 'label2', 'label3'),
             'upper right')
      The *loc* location codes are::
  
            'best' : 0,          (currently not supported for figure legends)
            '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,"""
  
  plt.show()
  