Animating bubble plots

Let's look at how to animate a bubble plot. This is useful when you want to visualize data that's transient and dynamic.

How to do it…

  1. Create a new Python file, and import the following packages:
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation 
  2. Let's define a tracker function that will dynamically update the bubble plot:
    def tracker(cur_num):
        # Get the current index 
        cur_index = cur_num % num_points
  3. Define the color:
        # Set the color of the datapoints 
        datapoints['color'][:, 3] = 1.0
  4. Update the size of the circles:
        # Update the size of the circles 
        datapoints['size'] += datapoints['growth']
  5. Update the position of the oldest datapoint in the set:
     # Update the position of the oldest datapoint ...

Get Python: Real World Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.