Adding Interactivity and Animating Plots

As a book focusing on the use of Matplotlib through elaborate examples, we opted to defer or simplify our discussion of the internals. For those of you who want to understand the nuts and bolts that make Matplotlib tick, you are advised to read Mastering matplotlib by Duncan M. McGreggor. At some point during our Matplotlib journey, it becomes inevitable for us to discuss more about backends, which turn plotting commands to graphics. These backends can be broadly classified as non-interactive or interactive. We will give examples that are pertinent to each backend class.

Matplotlib was not designed as an animation package from the get-go, thus it will appear sluggish in some advanced usages. For animation-centric applications, PyGame is a very good alternative (https://www.pygame.org); it supports OpenGL- and Direct3D-accelerated graphics for the ultimate speed in animating objects. Nevertheless, Matplotlib has acceptable performance most of the time, and we will guide you through the steps to create animations that are more engaging than static plots.

The examples in this chapter will be based on unemployment rates and earnings by educational attainment (2016), available from data.gov and curated by the Bureau of Labor Statistics, U.S. Department of Labor. Here is the outline of this chapter:

  • Scraping information from websites
  • Non-interactive backends
  • Interactive backends: Tkinter, Jupyter, and Plot.ly
  • Creating an animated plot
  • Exporting an animation as a video
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset