Here is my code:
from Trees import *
from timeit import default_timer as timer
import re
import matplotlib.pyplot as plt
import pickle
def read_file(file):
words = []
for line in wordFile:
for word in line.split():
words.append(re.sub("[^a-z]", "", word.lower()))
return words
def pickle_object(object, fileName):
with open(fileName, "wb") as output:
pickle.dump(object, output, pickle.HIGHEST_PROTOCOL)
wordFile = open("texts/words1.txt", "r")
wordList = read_file(wordFile)
baseTrie = Trie()
trie2 = Trie()
bst = BinarySearchTree()
avl = AVLTree()
for item in wordList:
baseTrie.add(item)
trieList = baseTrie.list("", [])
for word in trieList:
bst.put(word, None)
avl.put(word, None)
trie2.add(word)
start = timer()
testTrieList = trie2.list("", [])
end = timer()
trieTime = end - start
start = timer()
bst.inorder()
end = timer()
bstTime = end - start
start = timer()
avl.inorder()
end = timer()
avlTime = end - start
#pickle_object(baseTrie, "Pickled Trees/trie.pkl")
print("Trie tree took %s seconds" % (trieTime))
print("Binary Search Tree took %s seconds" % (bstTime))
print("AVL tree took %s seconds" % (avlTime))
plt.plot(100, trieTime, label="Trie")
plt.plot(bstTime, label="BST")
plt.plot(avlTime, label="AVL")
plt.legend()
plt.show()
I want to show the amount of time, in seconds, how long each of the time seconds took. However, whenever I try and run the file, it turns out like this: My plot.
Why aren't the lines showing?
P.S. My output:
>>> Trie tree took 0.0350674204940301 seconds
>>> Binary Search Tree took 0.028901715849401904 seconds
>>> AVL tree took 0.030507586039193013 seconds
