Naming the Axes of my Graph on iPython Using Matplotlib.pyplot I am new to data science. I use Anaconda on windows 7.
I plotted a sine curve by doing the following on iPython:

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(x)
plt.plot(x, y)


And I got this:

But when I got ready to name the axes, the curve disappeared. I wrote this code:

plt.xlabel("Time")


And I got this:

I also wrote this:

plt.ylabel("Speed")


And got this:


So my question is, how can I plot a curve with labelled axes? (In other words, I will like the x-axis to be Time, the y-axis to be Speed and the curve intact)
When you use matplotlib's plot function, it holds an object behind the scenes for you. You can change this object with more calls to plt and then only once everything has been done should you plt.show() the graph.

Here is a simply example that does what you want:

In [1]: import matplotlib.pyplot as plt
In [2]: import numpy as np                                                           

In [3]: x = np.linspace(0, 10, 100)                                                  
In [4]: y = x ** 2                                   


The following lines change the plot object, adding the axes labels - but we don't show it until all are complete...

In [5]: plt.plot(x, y)                                                               
Out[5]: [&lt;matplotlib.lines.Line2D at 0x7f3c896bb9b0&gt;]

In [6]: plt.xlabel("Time")                                                           
Out[6]: Text(0.5, 0, 'Time')

In [7]: plt.ylabel("Speed")  
Out[7]: Text(0, 0.5, 'Speed')


Now we are done, so show it:

In [8]: plt.show()                                                                  




Have a look here for a more thorough demo, which also shows the object explicitly and lets you better understand what is going on.