這個是matplotlib自定義的annotate方法的文本:
一、
1 def annotate(self, s, xy, *args, **kwargs): 2 a = mtext.Annotation(s, xy, *args, **kwargs) 3 a.set_transform(mtransforms.IdentityTransform()) 4 if 'clip_on' in kwargs: 5 a.set_clip_path(self.patch) 6 self._add_text(a) 7 return a
這個方法里面定義了annotate方法所使用的變量,其中*args是tuple,**kwargs是dict
二、
def __init__(self, s, xy, xytext=None, xycoords='data', textcoords=None, arrowprops=None, annotation_clip=None, **kwargs): """ Annotate the point *xy* with text *s*. 在點xy:(x,y)處注釋文本 s In the simplest form, the text is placed at *xy*. 在最簡單的形式中,文本是處在xy的坐標點處 Optionally, the text can be displayed in another position *xytext*.實際應用中,文本用xytext屬性來隨意定義文本所在的位置 An arrow pointing from the text to the annotated point *xy* can then be added by defining *arrowprops*. 可以增加從文本到注釋點xy的箭頭指向,箭頭樣式通過arrowprops屬性定義 Parameters ---------- s : str The text of the annotation. s:str類型,注釋的文本 xy : (float, float) The point *(x,y)* to annotate. xy: (float, float)坐標點,所要注釋所在的坐標點 xytext : (float, float), optional The position *(x,y)* to place the text at. If *None*, defaults to *xy*. xytext:(float, float)坐標點,可選,注釋文本所在的坐標點,默認是上面xy的坐標點 xycoords : str, `.Artist`, `.Transform`, callable or tuple, optional xycoords :str類型,Artist和Transform的matplotlib基類,元組,可選 The coordinate system that *xy* is given in. The following types of values are supported: 給定的xy坐標系統是由屬性xycoords來提供支持,該屬性以下值 - One of the following strings: ================= ============================================= Value Description ================= ============================================= 'figure points' Points from the lower left of the figure 距離圖層左下角的點數量,比如xy=(10,10)說明距離圖層左下方各10個點的位置 'figure pixels' Pixels from the lower left of the figure 距離圖層左下角的像素,比如xy=(10,10)說明距離圖層左下方各10個像素的位置 'figure fraction' Fraction of figure from lower left 距離圖層左下角的數字分數,也就是百分比。左下角是(0,0),右上角是(1,1)。如果xy=(0.5,0.6),也就是距離左下角橫坐標50%,縱坐標60% 'axes points' Points from lower left corner of axes 距離軸坐標左下角的點數量 'axes pixels' Pixels from lower left corner of axes 距離軸坐標左下角的像素 'axes fraction' Fraction of axes from lower left 距離軸坐標左下角的數字分數 'data' Use the coordinate system of the object being annotated (default) 使用實際的軸坐標的數據(默認) 'polar' *(theta,r)* if not native 'data' coordinates 使用極坐標系來處理,(弧度,長度) ================= ============================================= - An `.Artist`: *xy* is interpreted as a fraction of the artists `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower left corner of the bounding box and *(0.5, 1)* would be the center top of the bounding box. - A `.Transform` to transform *xy* to screen coordinates. - A function with one of the following signatures:: def transform(renderer) -> Bbox def transform(renderer) -> Transform where *renderer* is a `.RendererBase` subclass. The result of the function is interpreted like the `.Artist` and `.Transform` cases above. - A tuple *(xcoords, ycoords)* specifying separate coordinate systems for *x* and *y*. *xcoords* and *ycoords* must each be of one of the above described types. See :ref:`plotting-guide-annotation` for more details. Defaults to 'data'. textcoords : str, `.Artist`, `.Transform`, callable or tuple, optional The coordinate system that *xytext* is given in. textcoords :str類型,Artist和Transform的matplotlib基類,元組,可選,其值是與'xycoords'一致,並且也可以使用下面兩個值《主要定義偏移量的》,如果沒有說明,則與'xycoords'使用的坐標系統一致 All *xycoords* values are valid as well as the following strings: ================= ========================================= Value Description ================= ========================================= 'offset points' Offset (in points) from the *xy* value 'offset pixels' Offset (in pixels) from the *xy* value ================= ========================================= Defaults to the value of *xycoords*, i.e. use the same coordinate system for annotation point and text position. arrowprops : dict, optional The properties used to draw a `~matplotlib.patches.FancyArrowPatch` arrow between the positions *xy* and *xytext*. arrowprops : 字典類,可選。這個屬性主要是用來畫出xytext的文本坐標點到xy注釋點坐標點的箭頭指向線段 If *arrowprops* does not contain the key 'arrowstyle' the allowed keys are: 如果arrowprops 字典類中不包含arrowstyle的key,則可以使用下列的KEY ========== ====================================================== Key Description ========== ====================================================== width The width of the arrow in points 寬度:以點為單位定義連線的寬度 headwidth The width of the base of the arrow head in points 箭頭寬度:以點為單位定義箭頭的寬度 headlength The length of the arrow head in points 箭頭長度:以點為單位定義箭頭的長度 shrink Fraction of total length to shrink from both ends 縮小:移動提示,並使其離注釋點和文本一些距離 ? Any key to :class:`matplotlib.patches.FancyArrowPatch` 其他的matplotlib.patches.FancyArrowPatch基類中屬性 ========== ====================================================== If *arrowprops* contains the key 'arrowstyle' the above keys are forbidden. The allowed values of ``'arrowstyle'`` are: 如果arrowprops 字典類中包含arrowstyle的key,則可以使用下列的賦值 ============ ============================================= 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 ============ ============================================= Valid keys for `~matplotlib.patches.FancyArrowPatch` are: =============== ================================================== Key Description =============== ================================================== arrowstyle the arrow style 箭頭的樣式 connectionstyle the connection style 連接線的樣式 relpos default is (0.5, 0.5) 箭頭起始點相對注釋文本的位置,默認為 (0.5, 0.5),即文本的中心, (0,0)表示左下角,(1,1)表示右上角 patchA default is bounding box of the text 箭頭起點處的圖形(matplotlib.patches對象),默認是注釋文字框 patchB default is None 箭頭終點處的圖形(matplotlib.patches對象),默認為空 shrinkA default is 2 points 箭頭起點的縮進點數,默認為2 shrinkB default is 2 points 箭頭終點的縮進點數,默認為2 mutation_scale default is text size (in points) mutation_aspect default is 1. ? any key for :class:`matplotlib.patches.PathPatch` 其他matplotlib.patches.PathPatch的屬性 =============== ================================================== Defaults to None, i.e. no arrow is drawn. 默認是NONE,沒有任何箭頭繪制 annotation_clip : bool or None, optional annotation_clip : 布爾值或者NONE,可選 Whether to draw the annotation when the annotation point *xy* is 當注釋點xy在子圖區域外面是否要繪制注釋 outside the axes area. - If *True*, the annotation will only be drawn when *xy* is 設為True時,只有被注釋點在子圖區內時才繪制注釋; within the axes. - If *False*, the annotation will always be drawn. 設為False時,無論被注釋點在哪里都繪制注釋。 - If *None*, the annotation will only be drawn when *xy* is NONE:僅當xycoords為‘data’時,相當於True。 within the axes and *xycoords* is 'data'. Defaults to *None*. **kwargs Additional kwargs are passed to `~matplotlib.text.Text`. Returns ------- annotation : `.Annotation` See Also -------- :ref:`plotting-guide-annotation`. """ _AnnotationBase.__init__(self, xy, xycoords=xycoords, annotation_clip=annotation_clip) # warn about wonky input data