Reputation: 348
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
Upvotes: 4
Views: 7008
Reputation: 4479
You might want to install matplotlib
pip install matplotlib
or on Ubuntu
sudo apt-get install python3-matplotlib
Then, your code prints a simple line graph on my machine.
Upvotes: -2
Reputation: 949
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).
Upvotes: 3