Example: Gnuplot to Video (Finite Square Well Eigenvalues)

Gnuplot is a simple but powerful graphing tool available on most platforms. True, it is not a replacement for Maple, Mathematica, MATLAB or the like, but it can be quite useful for mass producing graphs, particularly when making them for a video. In this case, I'm going to make a video showing the dependence of eigenvalue function solutions on potential height for the finite square well problem.

First up, the tools needed are bash, gnuplot, mencoder (part of mplayer), bc (a common command line utility) and my rubbish. All of these except mencoder are probably installed by default under Linux. That said, I'll leave software management/installation to you.

Alright let's start. Expand the fsw gzip'd tarball ("tar -xzvf fsw.tgz"), you'll see a directory ("fsw") with a few files that start "mk". These are scripts. If you open "mkeven" in your editor of choice, you'll see this script loops a certain number of times and outputs two links for each iteration. One appears to be a filename, and the other seems to be the eigenvalue function for the finite square well problem. Whatever am I doing this for?

Let's face it, if you want a 25 frames per second video that lasts 30 seconds, you'll need 750 individual images (frames). Do you want to change the output filename and graphing function 750 times by hand? Well neither do I. This script allows me to create an output file that contains 750 commands without editing each line myself. All I have to do is run "bash mkeven > outputfilename". In this case, the output file is called "fswe.gp" (fswe for "finite square well - even" & gp for gnuplot, but you can call it "edward" if you fancy).

But what's this about "cat generic.gnuplot", you might ask. Well, some things need to be set for everything to look pretty. For example, I want to see a grid on my plots, and I'd like all graphs to have the same range in both x and y. Additionally, since I'm making a video, I should save my output as an image file png (or jpg, eps, etc.) and make some labels. There is nothing too complicated here, and, as it is the same stuff for even and odd parity graphs, I thought I'd avoid typing it twice.

Alright, everything make sense? Good. Let's give a quick look to the "fswe.gp" file. What you are seeing is a sequence of commands to gnuplot. In fact, you could start gnuplot and type these in one at a time and get the exact results we want, but that would be more painful than necessary. Instead type "gnuplot fswe.gp" to create all 750 png image files. Yes, it might take a couple seconds.

Done? Good. You're almost there. Now you have all the frames for your video and they are numbered sequentially. All we need to do now is type "bash mkMPNG" to make a motion PNG video. As all the pictures are already PNG, this should be very fast and the best quality. Sadly, not a lot of things support MPNG, so you might need to create a Xvid (DivX/MPEG4) version if you are going to share this with other people. I included a "mkXVID" script for this reason.

If all has gone well, you should have videos that look like these I uploaded to Google video.

even: http://video.google.com/videoplay?docid=-7420584363707202588&hl=en
odd: http://video.google.com/videoplay?docid=7277853444222174445&hl=en
both: http://video.google.com/videoplay?docid=-1462699438407102802&hl=en

You'll notice that the text of the Google video is mostly unreadable and the colors of the blue and green lines are indistinguishable on the video of both parity. These issues arise from the compression used by Google video. If you don't share your results via flash video or other extreme compression systems, this shouldn't be a problem for you.

Anyway, these scripts are pretty simple so you should be able to readily adapt them for any purpose you might need. And as you can see, as long as you can formulate your function and plot it in gnuplot, you can make it into a video.

AttachmentSize
fsw.tgz28.05 KB