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 datapoints['position'][cur_index] = np.random.uniform(0, 1, 2) datapoints['size'][cur_index] = 7 datapoints['color']...