网上的版本好像好久都没更新了treePlotter是没有人用了么。今天学习的时候发现有些地方已经改了,我改的是在python 3.6 上的运行版本,需要导入matplotlib.pyplot
import matplotlib.pyplot as plt
# 定义决策树决策结果属性
descisionNode = dict(boxstyle=‘sawtooth‘, fc=‘0.8‘)
leafNode = dict(boxstyle=‘round4‘, fc=‘0.8‘)
arrow_args = dict(arrowstyle=‘
# myTree = {‘no surfacing‘: {0: ‘no‘, 1: {‘flippers‘: {0: ‘no‘, 1: ‘yes‘}}}}
def plotNode(nodeTxt, centerPt, parentPt, nodeType):
# nodeTxt为要显示的文本,centerNode为文本中心点, nodeType为箭头所在的点, parentPt为指向文本的点
createPlot.ax1.annotate(nodeTxt, xy=parentPt, xycoords=‘axes fraction‘,
xytext=centerPt, textcoords=‘axes fraction‘,
va=‘center‘, ha=‘center‘, bbox=nodeType, arrowprops=arrow_args)
# def createPlot():
# fig = plt.figure(1, facecolor=‘white‘)
# fig.clf()
# #