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的artistloc:图例的位置。其值可以为字符串或者数字: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
学员评价