Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why matplotlib give the error [<matplotlib.lines.Line2D at 0x111fa5588>]?

I'm programming in python and I work on OS Yosemite with Anaconda: Conda Version: 3.15.1, Python Version: 3.4.3.final.0 and I have this problem with plot:

import matplotlib.pyplot as plt   
a=[1,2,3] 
b=[10,20,30]
plt.plot(a,b)
plt.show()

but I have the error: []. I read some other question about the same problem but I have not resolved my problem. Thanks in advance. Giuseppe

like image 251
Giuseppe Ricci Avatar asked Oct 24 '25 17:10

Giuseppe Ricci


2 Answers

You can try this before import

%matplotlib inline
like image 116
Danqing Avatar answered Oct 26 '25 06:10

Danqing


That isn't an error message. plt.plot returns a list of matplotlib.lines.Line2D objects. That object gets printed by the interpreter as:

<matplotlib.lines.Line2D object at ...>

This format is how the interpreter prints everything that doesn't have a method __repr__.

Its exactly the same as this example

>>> def f():
...     return 42
... 
>>> f()
42

Possibly these two classes might be a bit more illuminating:

>>> class C():
...     def __init__(self):
...         self.meaning_of_life = 42
... 
>>> class D():
...     def __init__(self):
...         self.meaning_of_life = 42
...     def __repr__(self):
...         return "Meaning = {}".format(self.meaning_of_life)
... 
>>> C()
<__main__.C object at 0x7f4a3255b8d0>
>>> D()
Meaning = 42

If the plot isn't showing then there is a problem elsewhere but it isn't related to that message (which should get printed after you call plt.plot not plt.show anyway).

like image 23
or1426 Avatar answered Oct 26 '25 06:10

or1426