Lecture 29

Matplotlib II

MCS 275 Spring 2022
Emily Dumas

Lecture 29: Matplotlib II

Course bulletins:

  • Project 3 due today at 6pm.
  • Next big topic is databases
  • Sprint break next week, no classes or office hours
  • Week after spring break:
    • Mon 28 Mar - no class, watch async Lecture 30 (SQLite I)
    • Wed 30 Mar - Guest lecturer Johnny Joyce: Crash Course on Machine Learning
    • Fri 1 Apr - no class, watch async Lecture 32 (SQLite II)
  • I won't hold office hours 28 Mar - 1 Apr
  • Mon 4 Apr - next time you see me in person

Gallery

The matplotlib home page has a nice gallery of examples with source code. It can be especially helpful if you know what you want something to look like, but don't know what it is called.

Broadcasting

This figure from §2.5 of Python Data Science Handbook by Jake VanderPlas was made with Matplotlib!

And the book contains the source code!

→ Matplotlib intro notebook ←

Main plotting commands

  • plt.plot(xvals,yvals,...) — plot line, points, or both
  • plt.scatter(xvals,yvals,...) — plot points with individual size/color control
  • plt.contour(xgrid,ygrid,zgrid) — contour (topographical) map of function of (x,y)
  • plt.imshow(zgrid,extent=[...],origin="lower") — density plot of a grid of values

Most other commands adjust or annotate plots made with these commands.

References

Revision history

  • 2022-03-18 Initial publication

Have a great spring break!