Lecture 25

Matplotlib II

MCS 275 Spring 2024
Emily Dumas

View as:   Presentation   ·   PDF-exportable  ·   Printable

Lecture 25: Matplotlib II

Reminders and announcements:

  • Project 3 is available!
  • Next big topics: databases and web programming
    • Using these is the "default" project 4 option
  • Homework 7, project 2 both to be returned soon.

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!

Today

  • Scatter plots
  • Contour plots
  • Density plots

→ Matplotlib demo 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

  • 2023-03-17 Finalization of the 2023 lecture this was based on
  • 2024-03-06 Initial publication