コード例 #1
0
def createPlot(inTree):
    fig = plt.figure(1, facecolor="white")
    fig.clf()
    axprops = dict(xticks=[], yticks=[])
    createPlot.ax1 = plt.subplot(111, frameon=False, **axprops)
    plotTree.totalW = float(trees.getNumberofLeafs(inTree))
    plotTree.totalD = float(trees.getTreeDepth(inTree))
    plotTree.xOff = -0.5/plotTree.totalW;
    plotTree.yOff = 1.0;
    plotTree(inTree, (0.5, 1.0), '')
    plt.show()
コード例 #2
0
def plotTree(myTree, parentPoint, nodeText):
    numLeafs = trees.getNumberofLeafs(myTree)
    depth = trees.getTreeDepth(myTree)
    firstStr = list(myTree.keys())[0]
    centerPoint = (plotTree.xOff + (1.0 + float(numLeafs))/2.0/plotTree.totalW, plotTree.yOff)
    plotMidText(centerPoint, parentPoint, nodeText)
    plotNode(firstStr, centerPoint, parentPoint, decisionNode)
    secondDict =  myTree[firstStr]
    plotTree.yOff = plotTree.yOff - 1.0/plotTree.totalD
    if(plotTree.yOff == 0) :
        print("problem")
    for key in secondDict.keys():
        plt.show()
        if type(secondDict[key]).__name__=='dict':
            plotTree(secondDict[key], centerPoint, str(key))
        else:
            plotTree.xOff = plotTree.xOff + 1.0/plotTree.totalW
            plotNode(secondDict[key], (plotTree.xOff, plotTree.yOff), centerPoint, leafNode)
            plotMidText((plotTree.xOff, plotTree.yOff), centerPoint, str(key))
    plotTree.yOff = plotTree.yOff + 1.0/plotTree.totalD