python画图笔记——注释

来源:互联网 发布:魔域老网络连接堵塞 编辑:程序博客网 时间:2024/06/11 18:02

一.注释简介

  • 注释位于matplotlib.pyplot下,需要需要实例化后再在画布上填写注释 import matplotlib.pyplot as
    plt fig=plt.figure() ax=fig.add_subplot(1,1,1)
  • 注释有三种,分别为 ax.text():文本注释,只能填写文本 ax.arrow():箭头标记,不能填写文本
    ax.annotate():箭头注释,在箭头的位置可以填写文本

二.参数解释

1.text

text(x, y, s, fontdict=None, withdash=False, **kwargs)
x,y:注释的坐标位置(标量)
s:注释的内容(字符串)
fontdict:重新设置注释内容的文本格式,包括字体颜色、背景大小和颜色、字体大小等(字典)
withdash:创建一个替代注释内容“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:`matplotlib.transforms.Bbox` instance  |        clip_on: [True | False]  |        clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.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-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]  |        style or fontstyle: [ 'normal' | 'italic' | 'oblique']  |        text: string or anything printable with '%s' conversion.  |        transform: :class:`~matplotlib.transforms.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' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]  |        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:`matplotlib.transforms.Bbox` instance   clip_on: [True | False]   clip_path: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.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.   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:`~matplotlib.transforms.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:如果箭头位置超出画布,是否画出来(布尔型)

三.续语

重要的和常用的都在这里了,如果后期有什么“新发现”和“更正”也会添加到这里,同时,因为是英文资料,如果博友们有什么心得和发现错误的地方请留言,多多交流

0 0
原创粉丝点击