top of page

Data Visualization Course Available Now

SJ Visualizer

Open source Python library to create engaging animated data visualizations for time series data ideal for sharing on Social Media.

​

GitHub: https://github.com/SjoerdTilmans/sjvisualizer

​

Like this project and want to support it? Please consider buying me a coffee.

​

Getting Started

Setup

Before starting we need to tick off a couple of prerequisites.

​

1. Have python installed on your computer. Python is THE programming language for data analysts and data scientists. It can be downloaded from here: https://www.python.org/

2. We need to install the sjvisualizer module. We can do this with python package manager pip. On windows you can install sjvisualizer using:

                    pip install sjvisualizer

​

To make sure it is installed successfully, you can type pip list in the command line. The sjvisualizer module should appear in the list.

Data Format

This python module will load data from Excel and expects it in a particular format. Is expects either dates or year numbers in the first column, each of the subsequent column headers are your data categories with the values for each date underneath. See the example below:

Data Example.png
Basic Bar Race

With only 2 lines of code you can make a basic data visualization. If you have your data in the format as explained above it is very simple. The code below can be used to create a very simple bar chart race with python. (this example can also be found in this GitHub repo: https://github.com/SjoerdTilmans/sjvisualizer/blob/main/Examples/basic_bar_race.py)

Adding custom images to each bar

To add custom images we do not need to do any coding! You might have noticed that the code has created an assets folder for us. You can drop image files (.png) in this folder and as long as they have the same name as our data categories, the script will automagically pick them up.

Images.png
Converting to a video

There are two options to convert the animation into a video:

  • Using a screen recorder, I use OBS Studio, which is open-source and free: https://obsproject.com/

  • Using the built in screen recorder in the software. Please note that this is a beta feature at the moment and will reduce the framerate of the animation. However, the generated mp4 file will be smooth during playback. To generate the mp4 set the optional argument "record=True" when calling the plot functions. For example:

Conclusion

Are you new to python or want to bring your skills to the next level? I have published a full beginner friendly course course on Udemy, go check it out!

​

The two lines of code above will import the plot module from sjvisualizer, which we can use to create an animation. In this case a bar chart race. This code will create an animation that should look like this:

Animated Pie Chart

Similarly as the bar race, we can use the same code structure to create an animated pie chart.

And the output for this one should look something like this:

Animated Line Chart

Sjvisualizer can also generate line charts. Please use the code blow.

And the output for this one should look something like this:

Animated Area Charts

The last chart type that sjvisualizer currently supports is the stacked area chart. See the example below.

And the output for this one should look something like this:

Adding custom colors

It is really simple to add custom colors to our visualization. We only need to provide a python dictionary containing the color information. The key of the dictionary should be the same as the name of the data category (column header in the Excel file). The value of the dictionary should be a list of the RGB values. These values represent the intensity of Red, Green, and Blue as a value between 0 and 255. In the example below we add custom colors to the line animation previously created. The same technique can be used for any chart type.

More advanced features

Using sjvisualizer, we can also create more custom data animations like the one below. For example, we can change the aspect ratio of the animation, add a background color, or add additional charts to the same animation.

I am currently working on documentation for the more advanced settings for sjvisualizer. In the mean time, please refer to the this example script: https://github.com/SjoerdTilmans/sjvisualizer-examples/tree/main/Military%20Budget

7 Years Experience (1).png

Please tag me on Instagram or LinkedIn if you use this to make your own visualization. I might reshare it with my followers.

Full Reference Guide

bottom of page