python画图笔记——注释
⼀.注释简介
注释位于matplotlib.pyplot下,需要需要实例化后再在画布上填写注释 import matplotlib.pyplot as plt fig=plt.figure() ax=fig.add_subplot(1,1,1)
注释有三种,分别为 ax.text():⽂本注释,只能填写⽂本 ax.arrow():箭头标记,不能填写⽂本 ax.annotate():箭头注释,在箭头的位置可以填写⽂本
⼆.参数解释
<
text(x, y, s, fontdict=None, withdash=False, **kwargs)
x,y:注释的坐标位置(标量)
s:注释的内容(字符串)
fontdict:重新设置注释内容的⽂本格式,包括字体颜⾊、背景⼤⼩和颜⾊、字体⼤⼩等(字典) withda
sh:创建⼀个替代注释内容“s”的对象,参照英⽂单词解释,这应该是⼀个破折号
**kwargs包括
|        agg_filter: unknown
|        alpha: float (0.0 transparent through 1.0 opaque)
|        animated: [True | False]
|        axes: an :class:`~matplotlib.axes.Axes` instance
|        backgroundcolor: any matplotlib color
|        bbox:FancyBboxPatch prop dict
|        clip_box: a :class:`ansforms.Bbox` instance
|        clip_on: [True | False]
|        clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~ansforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ]
|        color: any matplotlib color
|        contains: a callable function
|        family or fontfamily or fontname or name: [FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]
|        figure: a :class:`matplotlib.figure.Figure` instance
|        fontproperties or font_properties: a :class:`matplotlib.font_manager.FontProperties` instance
|        gid: an id string
|        horizontalalignment or ha: [ 'center' | 'right' | 'left' ]
|        label: string or anything printable with '%s' conversion.
|        linespacing: float (multiple of font size)
|        multialignment: ['left' | 'right' | 'center' ]
|        path_effects: unknown
|        picker: [None|float|boolean|callable]
|        position: (x,y)
|        rasterized: [True | False | None]
|        rotation: [ angle in degrees | 'vertical' | 'horizontal' ]
|        rotation_mode: unknown
|        size or fontsize: [size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ]
|        sketch_params: unknown
|        snap: unknown
|        stretch or fontstretch: [a numeric value in range 0-1000 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-exp  |        style or fontstyle: [ 'normal' | 'italic' | 'oblique']
|        text: string or anything printable with '%s' conversion.
|        transform::class:`~ansforms.Transform` instance
|        url: a url string
|        usetex: unknown
|        variant or fontvariant: [ 'normal' | 'small-caps' ]
|        verticalalignment or ma or va: [ 'center' | 'top' | 'bottom' | 'baseline' ]
|        visible: [True | False]
|        weight or fontweight: [a numeric value in range 0-1000 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' |        wrap: unknown
|        x: float
|        y: float
|        zorder: any number
其中⽐较常⽤的有:
va:垂直分布情况
ha:⽔平分布情况
bbox:给⽂字加上⼀个框⼦(例如:bbox=dict(facecolor=’red’, alpha=0.5))
fontsize:字体⼤⼩
2.arrow
arrow(x, y, dx, dy, hold=None, **kwargs)
x,y:箭头起点坐标
dx,dy:箭头终点到起到的距离
hold:未解
**kwargs
Constructor arguments
*width*: float (default: 0.001)
width of full arrow tail
*length_includes_head*: [True | False] (default: False)
True if head is to be counted in calculating the length.
*head_width*: float or None (default: 3*width)
total width of the full arrow head
*head_length*: float or None (default: 1.5 * head_width)
length of arrow head
*shape*: ['full', 'left', 'right'] (default: 'full')
draw the left-half, right-half, or full arrow
*overhang*: float (default: 0)
fraction that the arrow is swept back (0 overhang means
triangular shape). Can be negative or greater than one.
*head_starts_at_zero*: [True | False] (default: False)
if True, the head starts being drawn at coordinate 0
instead of ending at coordinate 0.
Other valid kwargs (inherited from :class:`Patch`) are:
agg_filter: unknown
alpha: float or None
animated: [True | False]
antialiased or aa: [True | False]  or None for default
axes: an :class:`~matplotlib.axes.Axes` instance
capstyle: ['butt' | 'round' | 'projecting']
clip_box: a :class:`ansforms.Bbox` instance
clip_on: [True | False]
clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~ansforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ]  color: matplotlib color spec
contains: a callable function
edgecolor or ec: mpl color spec, None, 'none', or 'auto'
facecolor or fc: mpl color spec, or None for default, or 'none' for no color
figure: a :class:`matplotlib.figure.Figure` instance
fill: [True | False]
gid: an id string
hatch: ['/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*']
joinstyle: ['miter' | 'round' | 'bevel']
label: string or anything printable with '%s' conversion.
python新手代码画图linestyle or ls: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) | ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | ``' '`` | ``''``]  linewidth or lw: float or None for default
path_effects: unknown
picker: [None|float|boolean|callable]
rasterized: [True | False | None]
sketch_params: unknown
snap: unknown
transform: :class:`~ansforms.Transform` instance
url: a url string
visible: [True | False]
zorder: any number
其中常⽤的有:
width:箭尾的宽度⼤⼩
length_includes_head:箭头是否计算为箭头标记的的长度
overhang:箭头两端突出部分的长度,0的时候就是个三⾓形
head_length,head_width:箭头的长度和宽度
3.annotate
annotate(*args, **kwargs)
s : 箭尾的注释
xy : 箭头坐标
xytext : 箭尾坐标
arrowprops:设置箭头标致的格式(字典),其中有个arrowstyle很重要
arrowstyle:
============ =============================================
Name Attrs
============ =============================================
'-' None
'->' head_length=0.4,head_width=0.2
'-[' widthB=1.0,lengthB=0.2,angleB=None
'|-|' widthA=1.0,widthB=1.0
'-|>' head_length=0.4,head_width=0.2
'<-' head_length=0.4,head_width=0.2
'<->' head_length=0.4,head_width=0.2
'<|-' head_length=0.4,head_width=0.2
'<|-|>' head_length=0.4,head_width=0.2
'fancy' head_length=0.4,head_width=0.4,tail_width=0.4
'simple' head_length=0.5,head_width=0.5,tail_width=0.2
'wedge' tail_width=0.3,shrink_factor=0.5
annotation_clip:如果箭头位置超出画布,是否画出来(布尔型)
三.续语
重要的和常⽤的都在这⾥了,如果后期有什么“新发现”和“更正”也会添加到这⾥,同时,因为是英⽂资料,如果博友们有什么⼼得和发现错误的地⽅请留⾔,多多交流

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。