Matplotlib CheatSheet

Matplotlib is used to plot graphs so it is often used alongside Numpy.

Always use:

import matplotlib.pyplot as plt

import numpy as np (assuming numpy is always used with matplotlib)

  • Plotting a 1D array:


  • Plotting a 2D array:

Colour images:

image = np.array([[0,1,2],[3,4,5]])

plt.imshow(image, cmap =      # creates the image based on the array image and  #cmap (colour map) jet

plt.colorbar()  #creates a legend bar  #displays the plot

  • Adding labels to the graphs:

plt.xlabel(“Insert label for x axis here”)

plt.ylabel(“Insert label for y axis here”) – Pyplot tutorial


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s