机器学习实战之决策树(二)在 python 中使用 Matplotlib 注解绘制树形图blog.csdn.net
微信公众号:
qiongjian0427qiongjian/Machine-learninggithub.com
运行环境:anaconda—jupyter notebook
Python版本:Python3
1. Matplotlib 注解
Matplotlib 提供了一个注解工具 annotations ,可以在数据图形上添加文本注释。注解通常用于解释数据的内容。
1.1 使用文本注解绘制决策树
import matplotlib.pyplot as plt
decisionNode = dict(boxstyle="sawtooth", fc="0.8") # boxstyle为文本框的类型,sawtooth是锯齿形,fc是边框线粗细
leafNode = dict(boxstyle="round4", fc="0.8") # round4表示圆形
arrow_args = dict(arrowstyle="
def plotNode(nodeTxt, centerPt, parentPt, nodeType):
# nodeTxt:节点文本, centerPt:子节点, parentPt:父节点, nodeType:节点样式
createPlot.axl.annotate(nodeTxt, xy=parentPt,xy