Original Source Here
Interactive Animated Visualization
Using AnimatPlot for Animating Graphs & Plots
Data Visualization helps in understanding different patterns, associations, visual insights from the data, etc. It is important because it uncovers the mystery behind the data tables in form of charts, graphs, and plots. There is N number of python libraries that help in visualizing the data like Matplotlib, Seaborn, etc.
What if I tell you that you can animate your visualizations? Pretty interesting right! How cool it will be if you can do that. Let’s unravel the mystery behind this and learn about how we can animate our regular plots.
AnimatPlot is an open-source python library that is built on top of Matplotlib and is used for creating highly interactive animated plots. In this article, we will explore some of the functionalities that AnimatPlot provides.
Let’s get started…
Installing required libraries
We will start by installing AnimatPlot using pip. The command given below will do that.
!pip install animatplot
Importing required libraries
In this step, we will import the required libraries for creating animated plots.
import numpy as np
import matplotlib.pyplot as plt
import animatplot as amp
The dataset that creates here will create a sine wave and then we will animate this sine wave. Similarly, we will also another dataset for showing multiple plots in a single graph.
x = np.linspace(0, 1, 50)
t = np.linspace(0, 1, 20)
X, T = np.meshgrid(x, t)
Y = np.sin(2*np.pi*(X+T))
Creating Animated Plot
This is the final step where we will create the plot and animate it.
block = amp.blocks.Line(X, Y)
anim = amp.Animation([block])
Now we will add controls to the plot.
timeline = amp.Timeline(t, units='s', fps=20)
block = amp.blocks.Line(X, Y)
anim = amp.Animation([block], timeline)
Similarly, now we will add more data and create multiple plots in a single chart.
x = np.linspace(-2, 2, 41)
y = np.linspace(-2, 2, 41)
t = np.linspace(0, 2*np.pi, 30)
X, Y, T = np.meshgrid(x, y, t)
data = np.sin(X*X+Y*Y-T)
line_data = data[20,:,:] fig, (ax1, ax2) = plt.subplots(1, 2)
for ax in [ax1, ax2]:
ax1.set_title('Cross Section: $y=0$')
ax2.set_title(r'$z=\sin(x^2+y^2-t)$')line_block = amp.blocks.Line(X[0,:,:], line_data,
block = amp.blocks.Pcolormesh(X[:,:,0], Y[:,:,0], data, ax=ax2, t_axis=2, vmin=-1, vmax=1)
timeline = amp.Timeline(t, fps=10)
anim = amp.Animation([block, line_block], timeline)
Here you can see that how we created animated plots and added interaction to them.
Go ahead try this with different data and created an animated visualization. In case you find any difficulty please let me know in the response section.
This article is in collaboration with Piyush Ingale.
Before You Go
Thanks for reading! If you want to get in touch with me, feel free to reach me at firstname.lastname@example.org or my LinkedIn Profile. You can view my Github profile for different data science projects and packages tutorials. Also, feel free to explore my profile and read different articles I have written related to Data Science.
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot