15分钟
Legend 类
matplotlib.legend.Legend
是图例类,它的基类是matplotlib.artist.Artist
。其构造函数为: Legend(parent, handles, labels, loc=None, numpoints=None, markerscale =None, markerfirst=True, scatterpoints=None, scatteryoffsets=None, prop=None, fontsize=None, borderpad =None, labelspacing=None, handlelength=None, handleheight=None, handletextpad=None, borderaxespad =None, columnspacing=None, ncol=1, mode=None, fancybox=None, shadow=None, title=None, framealpha =None, bbox_to_anchor=None, bbox_transform=None, frameon=None, handler_map=None) 其关键字参数为:
parent
:持有该legend
的artist
loc
:图例的位置。其值可以为字符串或者数字:best
或0:自动计算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:正中央
handle
:一个artist
列表,添加这些artist
到legend
中lebels
:一个字符串列表添加到legend
中prop
:字体属性fontsize
: 字体大小(只有prop
未设置时有效)markerscale
:marker
的缩放比例(相对于原始大小)markerfirst
: 如果为True
,则marker
放在label
左侧;否则marker
放在label
右侧numpoints
: the number of points in the legend for linescatterpoints
: the number of points in the legend for scatter plotscatteryoffsets
: a list of offsets for scatter symbols in legendframeon
: if True, draw a frame around the legend. If None, use rcfancybox
: if True, draw a frame with a round fancybox. If None, use rcshadow
: if True, draw a shadow behind legendframealpha
: If not None, alpha channel for the frame.ncol
: number of columnsborderpad
: the fractional whitespace inside the legend borderlabelspacing
: the vertical space between the legend entrieshandlelength
: the length of the legend handleshandleheight
: the height of the legend handleshandletextpad
: the pad between the legend handle and textborderaxespad
: the pad between the axes and legend bordercolumnspacing
:the spacing between columnstitle
: 图例的标题bbox_to_anchor
: the bbox that the legend will be anchored.bbox_transform
: the transform for the bbox. transAxes if Noneloc a location code- 其他关键字参数用于设置属性
属性为:
- 继承自
Artist
基类的属性:.alpha
、.animated
、.axes
、.clip_box
、..clip_on
、.clip_path
、.contains
、.figure
、.gid
、.label
、.picker
、.transform
、.url
、.visible
、.zorder
学员评价