If I put pyplot.show()
before I try to save an image, the file doesn't actually contain the image.
At first I thought it was a bug but then I switched pyplot.show()
and pyplot.savefig('foo5.png')
and it worked.
Here is an example code piece.
def plot(embeddings, labels):
assert embeddings.shape[0] >= len(labels), 'More labels than embeddings'
pyplot.figure(figsize=(20, 20)) # in inches
for i, label in enumerate(labels):
x, y = embeddings[i,:]
pyplot.scatter(x, y)
pyplot.annotate(label, xy=(x, y), xytext=(5, 2), textcoords='offset points',
ha='right', va='bottom')
pyplot.savefig('foo4.png')
pyplot.show()
pyplot.savefig('foo5.png')
books = [bookDictionary[i] for i in range(1, num_points2+1)]
plot(two_d_embeddings, books)
print( os.listdir() )
foo4.png is just fine, but foo5.png is blank.