Hands-On Guide To Animating Visualizations With Plotly

In this article, we will learn about the different animated graphs through plotly and implement each of them.

Visualization of data is a means of effectively communicating ideas and important information about the dataset. It is an important skill for a data scientist to have good data visualizations in the project. One of the reasons why visualizations are important is because they can be used to convey a lot about the data in a very easy manner since they are graphical in nature. To make these graphs more interesting and suitable for all, plotly allows us to animate these graphs. 

In this article, we will learn about the different animated graphs through plotly and implement each of them. 

Let us get started with plotly animations. The advantages of using this library are that it is available both in R and Python and they are easily integrated into Colab, R Studio and Jupyter notebook. Before we move on to the implementation, make sure you have installed the plotly library. You can install this with the pip command


Sign up for your weekly dose of what's up in emerging technology.

pip install plotly

Animated Bar Charts

Animations in plotly are a great way of analysing how data changes with time and can help you understand the distribution of data over a particular time period. Bar charts can be animated as follows. 

Download our Mobile App

The dataset

I will select a dataset with a time series to make the visualization more impactful. Here I have chosen the car dataset from Kaggle. You can download the dataset by clicking on this link

Let us load the dataset and import the required libraries

import pandas as pd
import numpy as np
import as px

As you see there are different car models and brands and the prices along with the year they were sold. Let us now plot an animated bar chart that represents the models according to the prices and the time. 

animated =,
animated.update_xaxes(title_text='car sales')

Along the x-axis, we have the price of the car and the y-axis is the model of the car. 

As you can see above, the animations are happening according to the year. The data for each year is shown as and when the time elapses. You can stop whenever needed or manually move the timeline if you wish. 


If you hover over the image in any part of the bar, you can see the year, the price, the colour and the model of the car that was sold

Animated Scatter plots

Now that we saw how the bar charts are animated, in a very similar manner we can animate our scatter plots as well. Since they are quite similar I will use the same dataset as used above even for this implementation. But here for the x-axis I will choose mileage and y-axis will denote the price of the car. 

animated = px.scatter(
animated.update_xaxes(title_text='car sales')

As you can see I have stopped the animations and hovering over a data point will give information about that data. 


Parallel plots

Parallel plots are a great way to understand the relationship between different categorical values. Since they are best suited for categorical data we will use another dataset here. I will use the waiter tips dataset that can be downloaded directly from the plotly library. 

import as px
tips =

Now, we can go ahead and build a parallel plot as follows

parallel = px.parallel_categories(tips, dimensions=['sex', 'smoker', 'day'],
                color="size", color_continuous_scale=px.colors.sequential.Inferno,
                labels={'sex':'gender', 'smoker':'Smokers', 'day':'day'})

This graph allows you to drag and drop, explore values and even highlight the different values. It is also a good technique to identify outliers in the dataset. 

Sunburst plot

This is a plot that allows you to plot pie charts in an interactive way. You can use group by statements well with these plots. These plots visualize data that moves from root outwards to the leaf. 

tips =
sunburst = go.Figure(go.Sunburst(
    labels=["Female", "Male", "Dinner", "Lunch","Sun","Sat","Mon","Thur","Fri","Tue","Wed"],
    parents=["", "", "Female", "Female", 'Male', 'Male',"Female","Male","Female","Male","Female"],
        tips.groupby(['sex', 'time','day']).tip.mean().values),

You can iteratively see the information in the pie chart and these can be great visualization tools for presentations and for analysing the categorical data. 

As you can see the tips on Friday for a female can be seen by hovering over the labels. 


In this article, we saw how to implement different methods for animating visualisations to give a better understanding of the project. With such visualization and charts, it makes a better impact on communicating the information hidden in the data and are easy to implement as well. 

More Great AIM Stories

Bhoomika Madhukar
I am an aspiring data scientist with a passion for teaching. I am a computer science graduate from Dayananda Sagar Institute. I have experience in building models in deep learning and reinforcement learning. My goal is to use AI in the field of education to make learning meaningful for everyone.

AIM Upcoming Events

Conference, in-person (Bangalore)
Rising 2023 | Women in Tech Conference
16-17th Mar, 2023

Early Bird Passes expire on 10th Feb

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
27-28th Apr, 2023

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox