plot is not defined


I started to use matplotlib library to get a graph. But when I use "plot(x,y)" it returns me that "plot is not defined".

To import , I used the following command:

from matplotlib import *

Any Suggestions?

This question is tagged with python

~ Asked on 2012-03-02 11:57:17

The Best Answer is


Change that import to

from matplotlib.pyplot import *

Note that this style of imports (from X import *) is generally discouraged. I would recommend using the following instead:

import matplotlib.pyplot as plt

~ Answered on 2012-03-02 12:03:20


If you want to use a function form a package or module in python you have to import and reference them. For example normally you do the following to draw 5 points( [1,5],[2,4],[3,3],[4,2],[5,1]) in the space:

import matplotlib.pyplot

In your solution

from matplotlib import*

This imports the package matplotlib and "plot is not defined" means there is no plot function in matplotlib you can access directly, but instead if you import as

from matplotlib.pyplot import *

Now you can use any function in matplotlib.pyplot without referencing them with matplotlib.pyplot.

I would recommend you to name imports you have, in this case you can prevent disambiguation and future problems with the same function names. The last and clean version of above example looks like:

import matplotlib.pyplot as plt

~ Answered on 2012-03-02 13:26:40

Most Viewed Questions: