Lecture 28

Matplotlib

MCS 275 Spring 2022
Emily Dumas

Lecture 28: Matplotlib

Course bulletins:

  • Project 3 due 6pm on Friday 18 March.
  • Remaining office hours before deadline:
    • Joyce, 3:00-4:00pm Wednesday
    • Dumas, 12:00-12:50pm Friday
  • I will not be reachable at all over the weekend. After that, $\sim$48 hour response time until 4 April.
  • Except for spring break, Johnny Joyce's availability unchanged.
  • Project 4 will allow you to choose a topic, use arbitrary online resources, and collaborate if you want.
  • Project 4's focus is on documentation. Half of the grade will be how well you document:
    • Your project topic
    • How I should test your project
    • What sources you used
    • What your individual contribution was

Install

You don't need to install anything if you want to use matplotlib in Google Colab. However, it's hard to work will file I/O in Colab, which can make that approach a pain. To install locally:


        python3 -m pip install matplotlib
    

Often paired with:


        python3 -m pip install numpy
        python3 -m pip install notebook
    

See official matplotlib install help.

Plots

MATLAB

MATLAB is a proprietary software package for numerical computation. It has its own language, and is popular in engineering and applied sciences. It was first released in 1984.

It quickly developed a reputation for making it easy to generate nice plots.

Matplotlib

matplotlib is a library for making 2D plots in Python. It was developed starting in 2003 by John Hunter (then a neurobiology postdoc), inspired by the plotting interface of MATLAB.

Today it is the most widely used plotting package for Python, and the Python+numpy+matplotlib "stack" is increasingly popular for applications where MATLAB was once dominant.

Ways to use matplotlib

Matplotlib can be used in several ways:

  • In scripts, with output to a file
  • In REPL, with plots opening in a GUI
  • In IPython notebook, where plots are shown directly in the notebook

Notebook

As with numpy, I'll do most of the intro as a series of coding demos in a notebook.

→ Matplotlib intro notebook ←

While I'll post the updated notebook after lecture, I suggest using Chapter 4 of VanderPlas as your primary reference because it has detailed explanatory text and sample code notebooks.

References

Revision history

  • 2022-03-16 Initial publication