Animated Information Graphics

with Python and Plotly

Andreas Stöckl
Towards Data Science

--

Image www.pexels.com

Animated information graphics of various datasets are a popular topic on youtube, for example, the channel

has almost a million subscribers. I will show in this article some examples of such infographics on my dataset of news articles from Austrian newspapers on politics, and how to create the animations with Python and Plotly (https://plot.ly/).

In the article https://medium.com/datadriveninvestor/topics-in-online-news-before-the-austrian-elections-2019-d981facbd0dd, I analyzed the topics before the elections. In this post, I want to look back at the news from the second half of the year 2019, and use animated graphics to analyze the news over time. I collected and analyzed more than 22,000 news articles from 12 Austrian online daily newspapers.

The first video shows day by day how often each party has been named up to that day. It is counted from July until the end of the year. In the end, the ÖVP is just ahead of the FPÖ and “NEOS” is clearly at the end.

In the second video, the number of times each party was mentioned per newspaper per week is shown. This is also shown animated for the entire second half of the year. It is noticeable that individual media have a clear preference for some parties, and for example, NEOS was mentioned very little outside of ORF. The week of the election of the National Council is clearly visible in the increased number of reports and mentions. The period of coalition negotiations after the election can be seen in the increased naming of the “Greens”. Many other aspects can often only be seen after watching the video several times.

In order not only to review the quantity of reporting I have also tried to show the dominant contents in further visualization. The most common words are shown in a “Wordcloud” day by day. The dominating personalities stand out clearly, but also the election period is clearly recognizable by the changing choice of words. Here, words such as “percent” or “election results” dominate.

Let us look at how the animations were created?

I loaded a data frame with the articles and some packages for data frame manipulation and date handling.

Dataframe with articles

After counting the mentions of the political parties in the articles the data frame was extended with a column for each party.

Extended data frame

Then some lists for the political parties, the newspapers, and the days to animate were created. For each party (and newspaper) the entries are summed up and a bar chart with “Plotly” is generated. These are labeled with the number of entries. To get smoother transitions of the animations, 15 intermediate steps are calculated between the bar charts of two days, which are interpolated linearly.

After some formatting and labeling of the graphics, they are saved as numbered PNG files. This sequence of images can then be assembled into a movie using software such as Adobe After Effects.

To create the “word animation” I used the Python package “Wordclouds” (https://github.com/amueller/word_cloud). This package calculates a “word cloud” for each day and saves it again as a sequence of PNG files.

Image by the author

In the end, I used After Effects to merge the videos shown above and added some captions.

--

--

University of Applied Sciences Upper Austria / School of Informatics, Communications and Media http://www.stoeckl.ai/profil/