What is the difference between importing matplotlib and matplotlib.pyplot?

Have a look at this codebase tree: matplotlib contains a library of code, while pyplot is only a file of this lib.

import matplotlib

will imports all the files inside this repo. For example to use it:

import matplotlib as mpl
mpl.pyplot.plot(...)

To import pyplot:

from matplotlib import pyplot as plt
# or
import matplotlib.pyplot as plt
plt.plot(...)

One question for you: what console do you use? I guess it's Ipython console or something?

Edit:

To import all:

from matplotlib import *
pyplot(...)

Why do I guess you are using Ipython? Ipython console imports all modules from numpy and some other libraries by default on launch, so that in Ipython console you can simple use: sqrt, instead of import math; math.sqrt, etc. matplotlib is imported in Ipython be default.


I don't know of any way to import all the functions from every submodule. Importing all the functions from a submodule is possible the way you suggested with e.g. from matplotlib.pyplot import *.

Be noted of a potential problem with importing every function; you may override imported functions by defining your own functions with the same name. E.g:

from matplotlib.pyplot import *

def plot():
    print "Hello!"

plot()

would output

Hello!