Home > MATLAB > Welcome!

Welcome!

Anyone who knows anything about presenting data will tell you that pie charts are rubbish.  Even their idiot cousins will tell you that 3D pie charts are even worse.  That got me thinking, “how bad can it get?”.  Sure you can choose garish colour schemes and glossy reflective coatings and transparency, but that has been done before.  By almost every two-bit data-viz charlatan in existence, judging by a Google Image search.  To break new ground in awfulness, we need to enter (cue atmospheric intro)… a new dimension!  In fact, we’re going to make the pie chart travel through time (woo!) with an animation.

The MathWorks, to their eternal shame, include a 3D pie chart function, pie3.  By combining it with their rotate function, we can enter into new levels of crappiness.

First, we draw the pie chart.  This code is tweaked from the example on the pie3 help page.


colormap(hsv(6))
x = [1 0.25 3 2.5 2 1];
explode = [0 1 0 0 0 1];
h = pie3(x, explode, repmat({''}, size(x)));

3D pie chart

Now we animate it.


n = 180;
mov(n) = getframe;
for i = 1:n
   rotate(h, [20 20], 360 / n);
   mov(i) = getframe;
end

MATLAB ships with the functions movie, to play back your animation, and movie2avi to export it to video.  For more web-friendlyness, we’re going to create an animated gif using movie2gif on the FEX.


movie2gif(mov, 'pie4.gif', 'DelayTime', 0.5 / n);

And there we have it.  (Click to see it in all its animated glory.)

4D Pie Chart joy

Now, having set the bar suitably low, I promise all future mosts will be more useful than this.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: