《机器学习实战》——在python中使用Matplotlib注解绘制树形图

# encoding=utf-8
#使用文本注解绘制树形图
import matplotlib.pyplot as plt

decisionNode = dict(boxstyle="sawtooth", fc="0.8")
leafNode = dict(boxstyle="round4", fc="0.8")
arrow_args = dict(arrowstyle="<-")
#上面三行代码定义文本框和箭头格式
#定义决策树决策结果的属性,用字典来定义,也可写作 decisionNode={boxstyle:'sawtooth',fc:'0.8'}
#其中boxstyle表示文本框类型,sawtooth是波浪型的,fc指的是注释框颜色的深度
#arrowstyle表示箭头的样式

def plotNode(nodeTxt, centerPt, parentPt, nodeType):#该函数执行了实际的绘图功能
#nodeTxt指要显示的文本,centerPt指的是文本中心点,parentPt指向文本中心的点
    createPlot.ax1.annotate(nodeTxt, xy=parentPt,  xycoords='axes fraction',
             xytext=centerPt, textcoords='axes fraction',
             va="center", ha="center", bbox=nodeType, arrowprops=arrow_args )


#

你可能感兴趣的:(python,机器学习,python,机器学习)