Matplotlib 2.x By Example
上QQ阅读APP看书,第一时间看更新

Importing the Matplotlib pyplot module

The Matplotlib package includes many modules, including artist that controls the aesthetics, and rcParams for setting default values. The Pyplot module is the plotting interface we will mostly deal with, which creates plots of data in an object-oriented manner.

By convention, we use the plt abbreviation when importing:

import matplotlib.pylot as plt

Don't forget to run the Jupyter Notebook cell magic %matplotlib inline to embed your figure in the output.

Don't use the pylab module!

The use of the pylab module is now discouraged, and generally replaced by the object-oriented (OO) interface. While pylab provides some convenience by importing matplotlib.pyplot and numpy under a single namespace. Many pylab examples are still found online today, but it is much better to call the Matplotlib.pyplot and numpy modules separately.