Line 18 tells Gnuplot to put faint gridlines that run the full width or height of the graph at every major tic mark. Line 17 sets the title at the top of the graph and nudges it down a bit from its default location. Since Gnuplot will choose the range and tic locations if they’re not specified, Lines 12, 13, and 14 set the range and spacing to get a consistent vertical axis every time I generate a graph. The numbers after the axis label in Line 11 nudge the label a little to the right, because I thought the default location was too far from the axis. Lines 11-14 cover the formatting of the vertical (y) axis. Line 8 tells Gnuplot to split the space between major tic marks into three parts and put minor tics at the splits. Using 356.2425 as the number of days in a year is overly precise, but I’m a big fan of the Gregorian calendar reform. The spacing between the major tic marks, in seconds.This is the January before the war began, and I chose this date to insure that the major tics marks fall on the usual quarterly start dates: January 1, April 1, July 1, and October 1. Where we should start counting: 2003-01. Line 7 sets the major tic marks and the labels to the start of every quarter, which is kind of tricky. Line 6 sets the format of the axis labels to a 3-letter abbreviation of the month name ( %b), new line ( \n), an apostrophe, and a 2-digit year ( %y). Line 5 says that the x-axis will consist of time values. Lines 5-8 cover the formatting of the horizontal (x) axis. The codes follow the conventions of the well-known strftime C library. Line 2 tells Gnuplot that some of the input data will be time values and that they will be formatted with a 4-digit year ( %Y) followed by a hyphen and a 2-digit month ( %m). Two of the other commands create variables for later use, an the final command creates the plot itself. As you can see, most of the commands “set” a Gnuplot parameter that controls either the input or output formatting. Like Perl, Python, and the shell, Gnuplot comments start with a hash mark (#). The file of Gnuplot commands that generates the graph is called “icasualties.gp.” 1: # input format for datesħ: set xtics "2003-01", 60*60*24*365.2425/4, "2008-12" # quarterlyġ9: set key at "2007-10",20 right width -3 samplen 1.5 boxĢ2: ustot = `perl -e '$s=0 while()print$s ' icasualties.txt`Ģ6: set label 3 "Data source: " at '2003-05',10 leftĢ9: set terminal aqua 0 title "Timeline" size 800 600\ģ1: plot "icasualties.txt" using 1:2 title sprintf("US only (%d)",ustot)\ģ2: with linespoints pointtype 2 linetype 3 linewidth 3,\ģ3: "icasualties.txt" using 1:($2 $3 $4) title sprintf("Coalition (%d)",tot)\ The “CO” column contains the count of military deaths from coalition countries other than the United States and United Kingdom. I think all columns but the last are self-explanatory. The columns are separated by spaces it doesn’t matter that the number of spaces differs from column to column or row to row. The first several lines of that file look like this: Month US UK CO The data for the graphs are stored in a file called “icasualties.txt” that I update every month. I’ve kept using it after switching back to Macintosh because it’s so good at producing the kinds of graphs common in science and engineering. I started using it when I switched to Linux in the mid ’90s because there were no good Excel-like programs on that platform. This makes it a bit difficult to learn, but because it allows sequences of commands to be stored in files, it makes the creation of several similarly-formatted graphs a snap. Gnuplot began its life as a terminal program, and it’s still driven by typed commands rather than by clicks and drags. I figured it was about time I showed how I do it. I get the data from and generate the chart using Gnuplot, the venerable Unix plotting program. Next post Previous post Automated charts with GnuplotĮvery month since the fall of 2006, I’ve written a post like this one, in which I include a chart of US and coalition fatalities.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |