How do I animate a bar chart?

Is there any easy way to have an animated bar chart (one where the heights of the bars change with time)? I currently have the following code:

α := 1/2
β := 1/2
γ := 0
δ := 0
ϵ := 0
ζ := 0
η := 1/2
θ := 1/2
w := 2 Pi

DSolve[{a'[t] == (-2 I*w/3) a[t], b'[t] + c'[t] + e'[t] == 0,
d'[t] + f'[t] + g'[t] == 0, b'[t] - c'[t] == (I*w/3) (b[t] - c[t]),
f'[t] - g'[t] == (I*w/3) (f[t] - g[t]),
b'[t] + c'[t] - 2 e'[t] == (I*w/3) (b[t] + c[t] - 2 e[t]),
2 d'[t] - f'[t] - g'[t] == (I*w/3) (2 d[t] - f[t] - g[t]),
h'[t] == (-2 I*w/3) h[t], a == α, b == β,
c == γ, d == δ, e == ϵ,
f == ζ, g == η, h == θ}, {a[t], b[t],
c[t], d[t], e[t], f[t], g[t], h[t]}, t]

Animate[Show[
BarChart[{{Re[a[t]] /. %, Im[a[t]] /. %}, {Re[b[t]] /. %,
Im[b[t]] /. %}, {Re[c[t]] /. %, Im[c[t]] /. %}, {Re[d[t]] /. %,
Im[d[t]] /. %}, {Re[e[t]] /. %, Im[e[t]] /. %}, {Re[f[t]] /. %,
Im[f[t]] /. %}, {Re[g[t]] /. %, Im[g[t]] /. %}, {Re[h[t]] /. %,
Im[h[t]] /. %}}], BoxRatios -> Automatic], {t, 0, 30},
AnimationRate -> 1, AnimationRunning -> False, RefreshRate -> 30]

I have 8 differential equations being solved, and the real and imaginary parts of each solution is being plotted, so there are 8x2 bars. Understandably, though, this gives me the error 'BarChart is not a type of graphics'. Any help would be greatly appreciated, and thanks in advance ;)

• There are a surprisingly large number of posts recently where Show is unnecessarily used. I'm wondering if these posts all originate from the same classroom and are due to (incorrect) teacher instruction. – Mike Honeychurch Nov 17 '15 at 23:36
• There's a lot of close votes here, but I cannot agree that the mistake is "simple". It's a matter of Animate localizing the variable t, while the output from DSolve has a different t in mind. I'm quite sure, a duplicate question (or rather one that points specifically to localization) should be here somewhere. – LLlAMnYP Nov 18 '15 at 9:15

There are two problems. One is that in your DSolve call, you should solve for the functions {a, b, ...} instead of the expressions {a[t], b[t],...}. (In my experience, it's almost always better this way.) The other is that to get the proper list structure for BarChart, you should use First@DSolve[..] to remove an unnecessary `{}.

dsol = First@
DSolve[{a'[t] == (-2 I*w/3) a[t], b'[t] + c'[t] + e'[t] == 0,
d'[t] + f'[t] + g'[t] == 0,
b'[t] - c'[t] == (I*w/3) (b[t] - c[t]),
f'[t] - g'[t] == (I*w/3) (f[t] - g[t]),
b'[t] + c'[t] - 2 e'[t] == (I*w/3) (b[t] + c[t] - 2 e[t]),
2 d'[t] - f'[t] - g'[t] == (I*w/3) (2 d[t] - f[t] - g[t]),
h'[t] == (-2 I*w/3) h[t], a == α, b == β,
c == γ, d == δ, e == ϵ,
f == ζ, g == η, h == θ},
{a, b, c, d, e, f, g, h}, t];

Animate[
BarChart[{{Re[a[t]], Im[a[t]]}, {Re[b[t]], Im[b[t]]},
{Re[c[t]], Im[c[t]]}, {Re[d[t]], Im[d[t]]},
{Re[e[t]], Im[e[t]]}, {Re[f[t]], Im[f[t]]},
{Re[g[t]], Im[g[t]]}, {Re[h[t]], Im[h[t]]}} /. dsol,
PlotRange -> 0.5 {-1, 1}, Frame -> True],
{t, 0, 30}, AnimationRate -> 1, AnimationRunning -> False,
RefreshRate -> 30] For those with V10.1+ and a fear of braces:

Animate[BarChart[ReIm@Through@{a, b, c, d, e, f, g, h}@t /. dsol,
PlotRange -> 0.5 {-1, 1}, Frame -> True], {t, 0, 30},
AnimationRate -> 1, AnimationRunning -> False, RefreshRate -> 30]
• Fantastic! Thanks for the help ;) – turbodiesel4598 Nov 17 '15 at 23:58
• @turbodiesel4598 You're welcome. – Michael E2 Nov 17 '15 at 23:59
• +1, please consider (ReIm[#@t] & /@ {a, b, c, d, e, f, g, h}) /. dsol – Kuba Nov 18 '15 at 7:37
• @Kuba Thanks, and my own version. For some reason I don't like ReIm. Maybe when they get to 30000 functions in WL, I'll feel more friendly to these trivial extensions of the language. (Also it's less work to copy/paste/replace than to think.) – Michael E2 Nov 18 '15 at 11:04
barData = Table[{RandomReal[], RandomReal[], RandomReal[]}, {5}];
Manipulate[
BarChart[barData[[i]]],
{i, 1, 5, 1}]

or

Animate[
BarChart[barData[[i]]],
{i, 1, 5, 1}]
• Maybe you meant this as a joke, but I don't see how this helps the OP solve the problem. (I guess it answers the title of the question, but not the body.) – Michael E2 Nov 17 '15 at 23:53
• The question poser seemed to know how to get the raw data to be plotted (from the differential equations) but was asking about animating a bar graph. My answer addresses everything the poser asked, and was listed in the title. – David G. Stork Nov 17 '15 at 23:56
• The OP does not have data to be plotted, not like barData. They have expressions that evaluate to numerical values. (That's the difference I see.) – Michael E2 Nov 17 '15 at 23:58