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…
- Create a new Python file, and import the following packages:
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation
- 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
- Define the color:
# Set the color of the datapoints datapoints['color'][:, 3] = 1.0
- Update the size of the circles:
# Update the size of the circles datapoints['size'] += datapoints['growth']
- Update the position of the oldest datapoint in the set:
# Update the position of the oldest datapoint ...
Get Python Machine Learning Cookbook 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.