why matplotlib give the error [<matplotlib.lines.Line2D object at 0x0392A9D0>]?

In Jupyter nodebook, you could just insert

%matplotlib inline

before you use matplotlib.


That isn't an error. That has created a plot object but you need to show the window. That's done using pyplot.show(). As stated in the comments, please do not use pylab, but use matplotlib.pyplot instead as pylab has been deprecated. As such, all you have to do is call:

plt.show()

Just for reproducibility, here's a trace from the Python REPL (using IPython):

In [1]: import matplotlib.pyplot as plt

In [2]: plt.plot([1,2,3,4])
Out[2]: [<matplotlib.lines.Line2D at 0x123245290>]

In [3]: plt.show()

We get:

enter image description here


What about in a Jupyter notebook?

If you are using this in a Jupyter notebook, instead of having to use show(), you can place the following in a separate cell after you import matplotlib.pyplot:

%matplotlib inline

This will automatically draw the figure once you create it and you will not have to use show() after you're done.