Active Hackathon

Create interactive presentations within the Python notebook with ipyVizzu

The "ipyvizzu" is an animated graphing tool for notebooks
Listen to this story

Storytelling is one of the most important skills of an Analyst because the analysis has to be communicated to the stakeholders. The best way to communicate the analysis obtained from the data is by telling the story of the data. Using animations as a result of communication methods can assist the audience in rapidly grasping the point and absorbing the message delivered by the teller. This article will introduce a python framework called ipyVizzu which will help to create animated analysis within the notebook itself for presentation. Following are the topics to be covered.

Table of contents

  1. Introduction to the ipyVizzu
  2. Creating presentations with ipyVizzu

Introduction to the ipyVizzu

The “ipyvizzu” is an animated graphing tool for notebooks like Jupyter, Google Colab, Databricks, Kaggle, and Deepnote, among others. It enables data scientists and analysts to use Python animation for data storytelling. It is based on Vizzu, an open-source Javascript/C++ charting toolkit.

THE BELAMY

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

There is a new “ipyvizzu” extension,” ipyvizzu-story”, that allows animated charts to be shown directly from notebooks. Because the syntax of ipyvizzu-story differs from that of “ipyvizzu”, we recommend starting with the” ipyvizzu-story” repo if you want to use animated charts to show your findings live or as an HTML file. It makes use of a generic DataViz engine to produce several types of charts and easily transition between them. It is intended for creating animated data tales since it allows viewers to quickly follow multiple viewpoints of the data.

Main characteristics:

  • Designed with animation in mind.
  • Defaults based on data visualisation best practices.
  • Works with Pandas dataframes, as well as JSON and inline data input.
  • The auto-scrolling function keeps the real chart in place while running many cells.

Are you looking for a complete repository of Python libraries used in data science, check out here.

Creating stories with ipyVizzu

The article will use data related to sales, it is a time series data for multiple products and sub-products. To use the ipyVizzu needed to be installed, so let’s start with installing dependency.

!pip install ipyvizzu-story

Importing dependencies required for this article

import numpy as np
import pandas as pd
from ipyvizzu import Data, Config, Style
from ipyvizzustory import Story, Slide, Step

Since the ipyvizzu module is completely compatible with Pandas dataframes, creating graphs straight from data is a breeze. To include a dataframe in an ipyvizzu chart, first, create a Data() object and then add the dataframe to it.

data = Data()
df=pd.read_csv(file_loc)
data.add_data_frame(data_utils)

We are all set to create stories with ipyVizzu story, for creating stories it must be in the form of slides. It’s similar to a video which is a set of different frames. 

stories = Story(data=data,style=chart_designs)

The plots could be designed according to the need, one change the labels, colours, font size of the texts, orientation of the labels, etc. To customize the plots use the below code.

chart_designs = Style(
    {
        "plot": {
            "paddingLeft": "0em",
            "yAxis": {
                "label": {
                    "fontSize": "1em",
                    "paddingRight": "1.2em",
                },
                "title": {"color": "#ffffff00"},
            },
            "xAxis": {
                "label": {
                    "angle": "2.5",
                    "fontSize": "1.1em",
                    "paddingRight": "0em",
                    "paddingTop": "1em",
                },
                "title": {"fontSize": "1em", "paddingTop": "2.5em"},
            },
        }
    }
)

To create a slide the components like x-axis, y-axis, hue and title need to be configured by using “channels”. As shown in the below code.

s_1 = Slide(
    Step(
        
        Config(
            {
                "channels": {
                    "y": {
                        "set": ["Sales", "Category"],
                        "range": {"min": "0%", "max": "100%"},
                    },
                    "x": {"set": ["order_Year"]},
                    "color": "Category",
                },
                "title": "Sales for all the caetgories",
                "geometry": "area",
            }
        ),
    )
)

Then after these slides are built, you need to add them to the story built above so that it can be aggregated in one place and be in a sequence. To display the story, use the play() function.

stories.add_slide(s_1)
stories.play()
(Note: Loading of GIF might take some time. Please hold on here)

Conclusion

The ipyVizzu is really simple and easy to use once its property is properly understood and one can create animated stories. With this article, we have understood the use of the ipyVizzu package. 

References

More Great AIM Stories

Sourabh Mehta
Sourabh has worked as a full-time data scientist for an ISP organisation, experienced in analysing patterns and their implementation in product development. He has a keen interest in developing solutions for real-time problems with the help of data both in this universe and metaverse.

Our Upcoming Events

Conference, Virtual
Genpact Analytics Career Day
3rd Sep

Conference, in-person (Bangalore)
Cypher 2022
21-23rd Sep

Conference, in-person (Bangalore)
Machine Learning Developers Summit (MLDS) 2023
19-20th Jan

Conference, in-person (Bangalore)
Data Engineering Summit (DES) 2023
21st Apr, 2023

3 Ways to Join our Community

Discord Server

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

Telegram Channel

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

Subscribe to our newsletter

Get the latest updates from AIM
MOST POPULAR

The curious case of Google Cloud revenue

Porat had earlier said that Google Cloud was putting in money to make more money, but even with the bucket-loads of money that it was making, profitability was still elusive.

Global Parliaments can do much more with Artificial Intelligence

The world is using AI to enhance the performance of its policymakers. India, too, has launched its own machine learning system NeVA, which at the moment is not fully implemented across the nation. How can we learn and adopt from the advancement in the Parliaments around the world? 

Why IISc wins?

IISc was selected as the world’s top research university, trumping some of the top Ivy League colleges in the QS World University Rankings 2022

[class^="wpforms-"]
[class^="wpforms-"]