matplotlib.pyplot: A MATLAB-like Python plotting package

matplotlib.pyplot

  • A collection of command style functions that make matplotlib work like MATLAB
  • After the pyplot object is instantiated, the commands are almost in one-to-one correspondence with MATLAB
  • To use "inline" in the Jupyter Notebook, use the cell magic command %matplotlib inline

Basic Example

In [1]:
%matplotlib inline

import matplotlib.pyplot as plt

plt.plot([0, 1, 2, 3])
plt.xlabel("Some Numbers");

Changing the plot style

In [2]:
plt.plot([0, 1, 2, 3])
plt.xlabel("Some Numbers");
plt.grid()

Use Numpy data

In [3]:
import numpy as np

t = np.arange(0,5,0.2)
plt.plot(t, t, 'b', t, t ** 2, 'b', t, t ** 3, 'r');

With style

In [4]:
import matplotlib

matplotlib.style.use('fivethirtyeight')
plt.plot(t, t, 'k', t, t ** 2, 'b', t, t ** 3, 'r');

Other stuff

  • Countour plots, surface plots
  • Other plotting libraries for Python