matplotlib---2.2Artist【primitive】
三、primitive
1.Line2D类
matplotlib.lines.Line2D类是matplotlib中的曲线类(基类是matplotlib.artist.Artist),它可以有各种各样的颜色、类型、以及标注等等。它的构造函数为:
Line2D(xdata, ydata, linewidth=None, linestyle=None, color=None, marker=None, markersize=None, markeredgewidth =None, markeredgecolor=None, markerfacecolor =None, markerfacecoloralt=’none’, fillstyle=None, antialiased=None, dash_capstyle=None, solid_capstyle=None, dash_joinstyle=None, solid_joinstyle=None, pickradius=5, drawstyle=None, markevery=None, **kwargs)
这些关键字参数都是Line2D的属性。其属性有:
-
继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、.picker、.transform、.url、.visible、.zorder -
.antialiased或者.aa属性:一个布尔值。如果为True则表示线条是抗锯齿处理的 -
.color或者.c属性:一个matplotlib color值,表示线条的颜色, -
.dash_capstyle属性:为'butt' or 'round' or 'projecting',表示虚线头端类型 -
.dash_joinstyle属性:为'miter' or 'round' or 'bevel',表示虚线连接处类型 -
.dashes属性:一个数值序列,表示虚线的实部、虚部的尺寸。如果为(None,None)则虚线成为实线 -
.drawstyle属性:为'default'or'steps'or'step-pre'or'step-mid'or'step-post',表示曲线类型。'default':点之间以直线连接'steps*':绘制阶梯图。其中steps等价于steps-pre,是为了保持兼容旧代码
-
.fillstyle属性:为'full'or'left'or'right'or'bottom'or'top'or'none'表示marker的填充类型。'full':填充整个markernone:不填充marker- 其他值:表示填充一半
marker
-
.linestyle或者ls属性:指定线型,可以为以下值:'-'或者'solid':表示实线'--'或者dashed:表示虚线'-.'或者dash_dot:表示点划线':'或者'dotted':表示点线'None'或者' '或者'':表示没有线条(不画线)
-
.linewidth或者lw属性:为浮点值,表示线条宽度 -
.marker属性:可以为一系列的字符串,如'.'、','、'o'....,表示线条的marker -
.markeredgecolor或者.mec属性:可以为matplotlib color,表示marker的边的颜色 -
.markeredgewidth或者.mew属性:可以为浮点数,表示marker边的宽度 -
.markerfacecolor或者.mfc属性:可以为matplotlib color,表示marker的前景色 -
.markerfacecoloralt或者.mfcalt属性:可以为matplotlib color,表示marker的可选前景色 -
.markersize或者.ms属性:可以为浮点数,表示marker的大小 -
.markevery属性:指定每隔多少个点绘制一个marker,可以为以下值:None:表示每个点都绘制markerN:表示每隔N个点绘制marker,从0开始(start,N):表示每隔N个点绘制marker,从start开始[i,j,m,n]:只有点i,j,m,n的marker绘制- ...其他值参考文档
-
.pickradius属性:浮点值,表示pick radius -
.solid_capstyle属性:可以为'butt'、'round'、'projecting',表示实线的头端类型 -
.sold_joinstyle属性:可以为'miter'、'round'、'bevel',表示实线连接处的类型 -
.xdata属性:可以为一维的numpy.array,表示x轴数据 -
.ydata属性:可以为一维的numpy.array,表示y轴数据
2.Text类
matplotlib.text.Text类是绘制文字的类(基类是matplotlib.artist.Artist)。它的构造函数为:
Text(x=0, y=0, text='', color=None, verticalalignment='baseline', horizontalalignment=’left’, multialignment=None, fontproperties =None, rotation=None, linespacing=None, rotation_ mode=None, usetex=None, wrap=False, **kwargs)
这些关键字参数也是属性。其属性有:
-
继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、.picker、.transform、.url、.visible、.zorder -
.backgroundcolor属性:背景色,可以为任何matplotlib color -
.bbox属性:文本框的边框。其值是FancyBboxPatch类的属性字典。 -
.color属性:字体颜色,可以为任何matplotlib color -
.family或者.name或者.fontfamily或者.fontname属性:字体的名字。可以是string或者string list(表示可以为若干个名字,优先级依次递减)。string必须是一个真实字体的名字,或者一个字体的class name。 -
.fontproperties或者.font_properties属性:字体的属性,值是一个matplotlib.font_manager.FontProperties实例(该实例一次性设置字体的很多属性,比如字体类型、字体名字、字体大小、宽度、...) -
.horizontalalignment或者.ha属性:水平对齐方式,可以为'center'、'right'、'left' -
.linespacing属性:为浮点数,单位为font size,表示行间距 -
.multialignment属性:multiline text对齐方式,可以为'left'、'right'、'center' -
.position属性:为一个元组(x,y),表示文本框的位置 -
.rotation属性:字体旋转角度。可以为下列值:- 浮点数,表示角度
'vertical'、'horizontal'
-
.rotation_mode属性:旋转模式。可以为下列值:'anchor':文本首先对齐,然后根据对齐点来旋转None:文本先旋转,再对齐
-
.size或者.fontsize属性:字体大小。可以为下列值:- 浮点值,表示字体大小
'xx-small'、'x-small'、'small'、'medium'、'large'、'x-large'、'xx-large'
-
.stretch或者.fontstretch属性:字体沿水平方向的拉伸。可以为下列值:- 整数,在[0---1000]之间
'ultra-condensed'、'extra-condensed'、'condensed'、'semi-condensed'、'normal'、'semi-expanded'、'expanded'、'extra-expanded'、'ultra-expanded'
-
.style或者.fontstyle属性:字体样式,可以为'normal'、'italic'、'oblique' -
.text属性:文本字符串,可以为任意字符串(他可以包含'\n'换行符或者LATEX语法) -
.variant或者.fontvariant属性:表示字体形变,可以为下列值:'normal'、'small-caps' -
.verticalalignment或者.ma或者.va属性:表示文本的垂直对齐,可以为下列值:'center'、'top'、'bottom'、'baseline'
-
.weight或者.fontweight属性:设置字体的weight,可以为下列值:- 一个整数值,在[0---1000]之间
'ultralight'、'light'、'normal'、'regular'、'book'、'medium'、'roman'、'semibold'、'demibold'、'demi'、'bold'、'heavy'、'extrabold'、'black'
-
.x属性:一个浮点值,表示文本框位置的x值 -
.y属性:一个浮点值,表示文本框位置的y值
3.Annotation类
matplotlib.text.Annotation类是图表中的图式,它是一个带箭头的文本框,用于解说图表中的图形。它的基类是matplotlib.text.Text和matplotlib.text._AnnotationBase。其构造函数为:
Annotation(s, xy, xytext=None, xycoords=’data’, textcoords=None, arrowprops =None, annotation_clip=None, **kwargs)
在位置xytext处放置一个文本框,该文本框用于解释点xy,文本框的文本为s。
-
s:文本框的文本字符串 -
xy:被解释的点的坐标 -
xytext:文本框放置的位置。如果为None,则默认取xy -
xycoords:xy坐标系,默认取'data'坐标系(即xy是数据坐标系中的点)。可以为以下值:'figure points':从figure左下角开始的点'figure pixesl':从figure左下角开始的像素值'figure fraction':(0,0)代表figure的左下角,(1,1)代表figure的右上角'axes points':从axes左下角开始的点'axes pixels':从axes左下角开始的像素'axes fraction':(0,0)代表axes的左下角,(1,1)代表axes的右上角'data':使用被标注对象的坐标系'offset points':指定从xy的偏移点'polar':极坐标系
-
textcoords:文本框坐标系(即xytext是文本坐标系中的点),默认等于xycoords -
arrowprops:指定文本框和被解释的点之间的箭头。如果不是None,则是一个字典,该字典设定了matplotlib.lines.Line2D的属性。- 如果该字典有一个
arrowstyle属性,则该键对应的值也是一个字典,创建一个FancyArrowsPatch实例,实例属性由该字典指定。 - 如果该字典没有
arrowstyle属性,则创建一个YAArrow实例,
- 如果该字典有一个
-
annotation_clip:控制超出axes区域的annotation的显示。如果为True则annotation只显示位于axes区域内的内容。 -
额外的关键字参数全部是设置
Text的属性
4.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 line为线条图图例条目创建的标记点数 -
scatterpoints: the number of points in the legend for scatter plot为散点图图例条目创建的标记点数 -
scatteryoffsets: a list of offsets for scatter symbols in legend为散点图图例条目创建的标记的垂直偏移量 -
frameon: if True, draw a frame around the legend. If None, use rc控制是否应在图例周围绘制框架 -
fancybox: if True, draw a frame with a round fancybox. If None, use rc控制是否应在构成图例北京的FancyBboxPatch周围启用圆边 -
shadow: if True, draw a shadow behind legend控制是否在图例后面画一个阴影 -
framealpha: If not None, alpha channel for the frame.控制图例框架的Alpha透明度 -
ncol: number of columns设置图例分为n列展示 -
borderpad: the fractional whitespace inside the legend border图例边框的内边距 -
labelspacing: the vertical space between the legend entries图例条目之间的垂直间距 -
handlelength: the length of the legend handles图例句柄的长度 -
handleheight: the height of the legend handles图例句柄的高度 -
handletextpad: the pad between the legend handle and text图例句柄和文本之间的间距 -
borderaxespad: the pad between the axes and legend border轴域图例边框之间的距离 -
columnspacing:the spacing between columns列间距 -
title: 图例的标题 -
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
5.Patch类
matplotlib.patches.Patch类是二维图形类。它的基类是matplotlib.artist.Artist。其构造函数为:
Patch(edgecolor=None, facecolor=None, color=None, linewidth=None, linestyle=None, antialiased=None, hatch=None, fill=True, capstyle=None, joinstyle=None, **kwargs)
参数为:
-
edgecolor:可以为matplotlib color,表示边线条的颜色,若为none则表示无颜色 -
facecolor:可以为matplotlib color,表示前景色,若为none则表示无颜色 -
color可以为matplotlib color,表示边线条和前景色的颜色。 -
linewidth:为浮点数,表示线条宽度 -
linestyle:指定线型,可以为以下值:'-'或者'solid':表示实线'--'或者dashed:表示虚线'-.'或者dash_dot:表示点划线':'或者'dotted':表示点线'None'或者' '或者'':表示没有线条(不画线)
-
antialiased:一个布尔值。如果为True则表示线条是抗锯齿处理的 -
hatch:设置hatching pattern,可以为下列的值:'\'、'|'、'-'、'+'、'x'、'o'、'0'、'.'、'*'
-
fill:为布尔值。如果为True则填充图形,否则不填充 -
capstyle:为'butt' or 'round' or 'projecting',表示线条头端类型 -
joinstyle:可以为'miter'、'round'、'bevel',表示矩形线条接头类型 -
其他关键字参数用于设置属性
如果
edgecolor, facecolor, linewidth, or antialiased为None则这些值从rc params中读取
属性如下:
-
继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、path_effects、.picker、.transform、.url、.visible、.zorder -
.antialiased或者.aa属性:一个布尔值。如果为True则表示线条是抗锯齿处理的 -
.capstyle属性:为'butt' or 'round' or 'projecting',表示线条头端类型 -
.color属性:可以为matplotlib color,表示边线条和前景色的颜色。 -
.edgecolor或者.ec属性:可以为matplotlib color,表示边线条的颜色,若为none则表示无颜色 -
.facecolor或者.fc属性:可以为matplotlib color,表示前景色,若为none则表示无颜色 -
.fill属性:为布尔值。如果为True则填充图形,否则不填充 -
.hatch属性:设置hatching pattern,可以为下列的值:'\'、'|'、'-'、'+'、'x'、'o'、'0'、'.'、'*'
-
.joinstyle属性:可以为'miter'、'round'、'bevel',表示矩形线条接头类型 -
.linestyle或者.ls属性:指定线型,可以为以下值:'-'或者'solid':表示实线'--'或者dashed:表示虚线'-.'或者dash_dot:表示点划线':'或者'dotted':表示点线'None'或者' '或者'':表示没有线条(不画线)
-
.linewidth或者.lw属性:为浮点数,表示线条宽度
6.Rectangle类
matplotlib.patches.Rectangle类是矩形类(基类是matplotlib.patches.Patch),其构造函数为:Rectangle(xy,width,height,angle=0.0,**kwargs)。
参数为:
xy:矩形左下角坐标width:矩形宽度height:矩形高度- 其他关键字参数用于设置属性
其属性有:
- 继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、.picker、.transform、.url、.visible、.zorder - 继承自
Patch基类的属性:.antialiased或者.aa、.capstyle、.color、.edgecolor或者.ec、.facecolor或者.fc、.fill、.hatch、.joinstyle、.linestyle或者.ls、.linewidth或者.lw属性
7.Polygon类
matplotlib.patches.Polygon类是多边形类。其基类是matplotlib.patches.Patch。其构造函数为: Polygon(xy, closed=True, **kwargs)。
参数为:
xy是一个N×2的numpy array,为多边形的顶点。closed为True则指定多边形将起点和终点重合从而显式关闭多边形。- 其他关键字参数用于设置属性
Polygon的属性有:
- 继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、.picker、.transform、.url、.visible、.zorder - 继承自
Patch基类的属性:.antialiased或者.aa、.capstyle、.color、.edgecolor或者.ec、.facecolor或者.fc、.fill、.hatch、.joinstyle、.linestyle或者.ls、.linewidth或者.lw属性
8.PolyCollection类
matplotlib.collections.PolyCollection是多边形集合类,其基类是matplotlib.collections._CollectionWithSizes。它的构造函数为:PolyCollection(verts, sizes=None, closed=True, **kwargs)。
其关键字参数为:
verts:一个顶点序列。每个顶点都由xy元组或者xy数组组成sizes:一个浮点数序列,依次指定每个顶点正方形的边长。如果序列长度小于顶点长度,则循环从序列头部再开始 挑选closed:如果为True,则显式封闭多边形edgecolors:collection的边的颜色- 其他关键字参数用于设置属性
下面为属性:
- 继承自
Artist基类的属性:.alpha、.animated、.axes、.clip_box、..clip_on、.clip_path、.contains、.figure、.gid、.label、.picker、.transform、.url、.visible、.zorder .facecolors:collection的前景色.linewidths:collection的边线宽.antialiaseds:抗锯齿属性,可以为True或者False.offsets: 设置collection的偏移.norm: 归一化对象.cmap:color map
浙公网安备 33010602011771号