1

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
1
  • what's the output of your prints? Commented May 19, 2016 at 8:27

1 Answer 1

1

I would go like this

abscissae = (10, 20, 30)
labels = ('Trie', 'BST', 'AVL')

plt.scatter(abscissae, (trieTime, bstTime, avlTime))
### E D I T — we want to compare the different timings, not the differences 
###           with respect to an arbitrary baseline!
plt.ylim(ymin=0)
plt.xticks(abscissae, labels)
plt.grid()
plt.show()

to obtain enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.