Blank Figure in Pyplot
<p>I use the below function, I get the plot shown in the window but the figure saved is blank. </p>

<pre><code>import matplotlib.pyplot as plt
from sklearn.manifold import TSNE

def plot_embeddings(embeddings, names):
model = TSNE(n_components=2, random_state=0)
vectors = model.fit_transform(embeddings)
x, y = vectors[:, 0], vectors[:, 1]
fig, ax = plt.subplots()
ax.scatter(x, y)
for i, tname in enumerate(names):
    ax.annotate(tname, (x[i], y[i]))
plt.show()
plt.savefig('foo.png', bbox_inches='tight')
</code></pre>

<p>I haven't found a solution that works.</p>

<p>Use <code>savefig()</code> before <code>show()</code> </p>

<p><code>show()</code> open window and wait till you close it and maybe when it closes window then it clears image.</p>

python matplotlib plot figure