Simply put, pyplot
is a submodule of matplotlib
which will not automatically be imported just because you import matplotlib
.
When you run import matplotlib as mpl
, only a specific set of methods will be imported, i.e. you could use mpl.use()
or mpl.rc_params
afterwards. If you are interested in what exactly is available to you after importing, try:
print(dir(mpl))
When you run from matplotlib import *
, the same methods as before are available, just without the mpl.
prefix. That's why you should usually not do this, as you may have planned to write your own function called use()
.
If you want to actually plot, you'll need to import pyplot
explicitly, i.e add either:
from matplotlib import pyplot
or:
import matplotlib.pyplot as plt
Important sidenote: importing matplotlib.pyplot
actually further populates the mpl
namespace; only when importing both matplotlib as mpl
as well as matplotlib.pyplot
, you'll get access to the mpl.ticker
module. If you don't import pyplot
explicitly, you'll get an AttributeError: "module 'matplotlib' has no attribute 'ticker'"
Suggested reading regarding the use of namespaces in python