Reputation: 15
I am trying to display a plot in Jupyter Notebook.
When I call plt.show() the first time everything is fine, but when I call it later on, in a different cell, it doesn't show the plot.
I am using %matplotlib inline.
Cell 1
fig, ax = plt.subplots()
ax.set_title("Scatter Plot x1, x2")
ax.set_xlabel("x1")
ax.set_ylabel("x2")
ax.scatter(df["x1"], df["x2"], c=df["c"])
plt.show()
Cell 2, here i add a new point and want to get the new plot.
ax.scatter(center0[0], center0[1], c="red")
plt.show()
If i remove the plt.show() statement in the cell 2 i get
<matplotlib.collections.PathCollection at 0x7efd696b9e20>
so the plot is there, but it wont display?
Upvotes: 0
Views: 269
Reputation: 24
you don't need to plot again actually, you just need to call your fig
Cell 1:
fig, ax = plt.subplots()
ax.set_title("Scatter Plot x1, x2")
ax.set_xlabel("x1")
ax.set_ylabel("x2")
ax.scatter(df["x1"], df["x2"], c=df["c"])
plt.show()
Cell 2:
ax.scatter(center0[0], center0[1], c="red")
fig
I hope it answers your question
Upvotes: 1