python之标注

# annotate():标注
import matplotlib.pyplot as plt
plt.figure(1,figsize=(5,5))
# frameon:是否绘制坐标轴的边框
plt.subplot(111,frameon=False)
# bbox:边框属性
# boxstyle:标注框样式(round、square、round4、roundtooth)
# facecolor:标注框填充色(white)
# edgewidth、edgecolor:标注框粗细、颜色
bbox1 = {'boxstyle':'round','facecolor':'white'}
bbox2 = {'boxstyle':'square','facecolor':'white'}
# arrowprops:箭头属性
# arrowstyle:箭头样式(-、<-、->、<|-、<->、<|-|>)
arrow_props = {'arrowstyle':'<-'}
def plotDraw(txt,xy,xytext,boxNature):
    # xy:被标注的点坐标,xytext:标注框的坐标,标注框对齐方式:水平(va)、垂直(ha)
plt.annotate(txt,xy,xytext,bbox=boxNature,arrowprops=arrow_props,va='center',ha='center',fontproperties='SimHei',fontsize=12)
plotDraw('父节点',(0.1,0.5),(0.5,0.1),bbox1)
plotDraw('叶节点',(0.3,0.8),(0.8,0.1),bbox2)
plt.show()

 

你可能感兴趣的:(python之标注)