I am working on a program to create a decision tree. The following method below should save an image of the tree:
def save_image(clf_, filename, feat_names, class_names, show=True):
"""Plot the tree and save to file."""
plt.figure(dpi=200)
tree.plot_tree(
clf_, filled=True,
feature_names=feat_names,
class_names=class_names
)
plt.savefig(f'{filename}.png')
if show:
plt.show()
Expected:
Output image of full tree
Actual:
The image outputted is not what is expected. How can I trouble-shoot this problem?