Why can't I get a plot using plot(arange(10)) in Python?

plot
python

#1

Hello,

I am new to Data science in Python and I was trying to make a simple plot using the code

plot(arange(10))

I have already imported pandas,numpy, matplotlib, pylab.

but I dont seem to get a plot as an output. I am only getting this

matplotlib.lines.Line2D at 0x7fb2240444d0

Is there something else I need to import for this to work? What is wrong here?

Thanks


#2

Which environment are you currently using to plot this?

Your output would be most likely sitting in a new pop-up / window.

If you are using iPython environment, you can try invoking inline mode to see the output in the same window.

ipython notebook --pylab=inline

Hope this helps.

Kunal


#3

I am using iPython environment and I already tried using

ipython notebook --pylab=inline

It gives an error in the terminal saying

[E 16:30:41.670 NotebookApp] Support for specifying --pylab on the command line has been removed.
[E 16:30:41.670 NotebookApp] Please use %pylab inline or %matplotlib inline in the notebook itself.

I then used

ipython notebook %pylab inline

and run the code again, but still can’t see any plot.


#4

Try using:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import pylab as p

plt.plot(np.arange(5))

#5

import matplotlib.pyplot as plt
import numpy as np
import pylab as p

plt.plot(np.arange(5))
plt.show()


#6

import matplotlib.pyplot as plt
import numpy as np

plt.plot(np.arange(6))
plt.show()


#7

Hi Ravi,

This works for me in jupyter…

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

plt.plot(np.arange(10));