| 22 | return numLeafs |
| 23 | |
| 24 | def getTreeDepth(myTree): |
| 25 | maxDepth = 0 |
| 26 | firstStr = myTree.keys()[0] |
| 27 | secondDict = myTree[firstStr] |
| 28 | for key in secondDict.keys(): |
| 29 | if type(secondDict[key]).__name__=='dict':#test to see if the nodes are dictonaires, if not they are leaf nodes |
| 30 | thisDepth = 1 + getTreeDepth(secondDict[key]) |
| 31 | else: thisDepth = 1 |
| 32 | if thisDepth > maxDepth: maxDepth = thisDepth |
| 33 | return maxDepth |
| 34 | |
| 35 | def plotNode(nodeTxt, centerPt, parentPt, nodeType): |
| 36 | createPlot.ax1.annotate(nodeTxt, xy=parentPt, xycoords='axes fraction', |