Moppentapper Moppentapper - 9 months ago 33
Python Question

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

I'm still fairly new to python and am wondering if the x.y statement means y is a submodule of x? And if so, doesn't the command:

import matplotlib.pyplot as plt

only import this particular submodule and nothing else? I had to do this in order to get access to the
function. How does that affect the modules normally imported when calling
import matplotlib as plt
? Can I get all the modules in matplotlib together under the plt name?

I'm aware that this question is related to what is the difference between importing python sub-modules from NumPy, matplotlib packages But the answer in this question does not tell me if nothing else in matplotlib is imported and how to just import all of matplotlib without worrying about submodules being left out.


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!"


would output