文本和注解
#文本
plt.text( 1,0.25, 'this', ha='right',va='top', rotation=45, size=16,color='g', alpha=0.5)
xycoords
#數(shù)據(jù)坐標(biāo)系
plt.annotate( r'$cos(\frac{\pi}{2})$', xy=(-np.pi/2,0),
xycoords='data', xytext=(-50,50),
textcoords='offset points', fontsize=14,
arrowprops=dict( arrowstyle='-|>',
connectionstyle='arc3,rad=1') )
image
annotate()注解
s:str, 注釋信息內(nèi)容
xy:(float,float), 被注釋的坐標(biāo)點(diǎn),二維元組形如(x,y)
xytext:(float,float), 注釋內(nèi)容的坐標(biāo)位置阵翎,注釋文本的坐標(biāo)點(diǎn),也是二維元組逢并,默認(rèn)與xy相同
xytext:注釋文本的坐標(biāo)點(diǎn),也是二維元組郭卫,默認(rèn)與xy相同
xycoords:被注釋點(diǎn)的坐標(biāo)系屬性筒狠,允許輸入的值如下:
屬性值 | 含義 |
---|---|
'figure points' | 以繪圖區(qū)左下角為參考,單位是點(diǎn)數(shù) |
'figure pixels' | 以繪圖區(qū)左下角為參考箱沦,單位是像素?cái)?shù) |
'figure fraction' | 以繪圖區(qū)左下角為參考辩恼,單位是百分比 |
'axes points' | 以子繪圖區(qū)左下角為參考,單位是點(diǎn)數(shù)(一個(gè)figure可以有多個(gè)axex谓形,默認(rèn)為1個(gè)) |
'axes pixels' | 以子繪圖區(qū)左下角為參考灶伊,單位是像素?cái)?shù) |
'axes fraction' | 以子繪圖區(qū)左下角為參考,單位是百分比 |
'data' | 以被注釋的坐標(biāo)點(diǎn)xy為參考 (默認(rèn)值) |
'polar' | 不使用本地?cái)?shù)據(jù)坐標(biāo)系寒跳,使用極坐標(biāo)系 |
-
weight
- str or int, 設(shè)置字體線型聘萨,
- 其中字符串從小到大可選項(xiàng)有{'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'}
-
textcoords :
注釋文本的坐標(biāo)系屬性,默認(rèn)與xycoords屬性值相同童太,也可設(shè)為不同的值米辐。
除了允許輸入xycoords的屬性值胸完,還允許輸入以下兩種:
屬性值 | 含義 |
---|---|
'offset points' | 相對(duì)于被注釋點(diǎn)xy的偏移量(單位是點(diǎn)) |
'offset pixels' | 相對(duì)于被注釋點(diǎn)xy的偏移量(單位是像素) |
-
arrowprops:dict,設(shè)置指向箭頭的參數(shù)翘贮,字典中key值有
- arrowstyle:設(shè)置箭頭的樣式赊窥,其value候選項(xiàng)如'->','|-|','-|>',也可以用字符串'simple','fancy'等,詳情見(jiàn)頂部的官方項(xiàng)目地址鏈接狸页。
關(guān)鍵字 | 說(shuō)明 |
---|---|
width | 箭頭的寬度(單位是點(diǎn)) |
headwidth | 箭頭頭部的寬度(點(diǎn)) |
headlength | 箭頭頭部的長(zhǎng)度(點(diǎn)) |
shrink | 箭頭兩端收縮的百分比(占總長(zhǎng)) |
如果設(shè)置了‘a(chǎn)rrowstyle’關(guān)鍵字锨能,以上關(guān)鍵字就不能使用。允許的值有:
箭頭的樣式 | 屬性 |
---|---|
'-' | 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 |
2. connectionstyle:設(shè)置箭頭的形狀芍耘,為直線或者曲線址遇,候選項(xiàng)有'arc3','arc','angle','angle3',可以防止箭頭被曲線內(nèi)容遮擋
3.color:設(shè)置箭頭顏色斋竞,見(jiàn)前面的color參數(shù)倔约。
后記:
有需要的朋友可以搜索微信公眾號(hào):【知音庫(kù)】
同時(shí)也是為了鼓勵(lì)自己,堅(jiān)持寫(xiě)筆記坝初,希望可以共同進(jìn)步跺株。