1. 程式人生 > >python畫圖的圖例legend設定。

python畫圖的圖例legend設定。

  1,位置。loc=‘upper right’ 或者loc=1這樣設定。還有如下備選項。

             'best':         0,  # only implemented for axes 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,

  2,利用bbox_to_anchor這個引數,可以把圖例放在圖外面。見這裡

  3,設定透明的圖例,見這裡

  4,設定圖例字型大小,fontsize引數 : int or float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’},只有這7種調節值。
  也可以利用prop引數:先定義font1 = {'size': 15}

。然後令引數prop=font1,這樣可以隨意調整字型大小。

  下面這些是他的所有引數。

def __init__(self, parent, handles, labels,
                 loc=None,
                 numpoints=None,    # the number of points in the legend line
                 markerscale=None,  # the relative size of legend markers
                                    # vs. original
markerfirst=True, # controls ordering (left-to-right) of # legend marker and label scatterpoints=None, # number of scatter points scatteryoffsets=None, prop=None, # properties for the legend texts fontsize=None, # keyword to set font size directly # spacing & pad defined as a fraction of the font-size borderpad=None, # the whitespace inside the legend border labelspacing=None, # the vertical space between the legend # entries handlelength=None, # the length of the legend handles handleheight=None, # the height of the legend handles handletextpad=None, # the pad between the legend handle # and text borderaxespad=None, # the pad between the axes and legend # border columnspacing=None, # spacing between columns ncol=1, # number of columns mode=None, # mode for horizontal distribution of columns. # None, "expand" fancybox=None, # True use a fancy box, false use a rounded # box, none use rc shadow=None, title=None, # set a title for the legend framealpha=None, # set frame alpha edgecolor=None, # frame patch edgecolor facecolor=None, # frame patch facecolor bbox_to_anchor=None, # bbox that the legend will be anchored. bbox_transform=None, # transform for the bbox frameon=None, # draw frame handler_map=None, ):