File Exchange Pick of the Week

Our best user submissions

Racing bar charts

Jiro‘s Pick this week is barChartRace by Eiji Konaka.

This an example of a nice outcome that spawned from a community discussion. It all started with this tweet.

Translation: “Is there a simple MATLAB function that could easily create this animation? I want it…”

I learned that this type of animation, where the bars switch places based on the order, is called Bar Chart Race.

My colleague, Michio, replied to the tweet saying that you can do some graphical updates with the barh function.

Michio created a sample, which he explained in a Japanese technical community site (in Japanese). This inspired Eiji to create his barChartRace, and he also wrote about it here (in Japanese).

So, let’s see this in action. I made some modifications to Eiji’s function to include an option to display the time stamp in the title, and to reverse the order of the bars. Here is an example of the FIFA World Rankings from 1993 to 2018. The rankings are based on the data from

load data y time countries

Opt.xTickLabelStrs = countries;
Opt.titleStr='FIFA World Ranking';
Opt.time = time;
Opt.yDir = 'reverse';

barChartRace(y, Opt)

It was great to see the communication and collaboration that happened over social media. By the way, Michio went ahead and extended his version of the bar chart race to include a few other options. You can find it here.


Give it a try and let us know what you think here or leave a comment for Eiji.

Published with MATLAB® R2019b

  • print
  • send email


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.