Working with gnuplot
anomit | July 5, 2008I had to plot a graph for the result of the simulation models I am running. The output happens to be something like the following for a simple model consisting of just a single HTTP server and another client requesting HTTP data with certain probability distributions that specify the number of page requests in a session and also the number of objects that would be there on a requested page. Actually it uses the dml configuration file included with the SSFNet WWW package in the test directory. This is how it looks if simulated for 3600 seconds:
199.27878718 [ sid 0 start 89.99831406 ] clnt 1 srv 2(0) #pages: 3 #objects: 28 total: 395466B seconds: 109.28047312 SUCCESS
346.0642575 [ sid 1 start 345.81315335 ] clnt 1 srv 2(0) #pages: 1 #objects: 2 total: 18603B seconds: 0.25110415 SUCCESS
1311.24547598 [ sid 2 start 901.76614728 ] clnt 1 srv 2(0) #pages: 2 #objects: 725 total: 5925458B seconds: 409.4793287 SUCCESS
1339.09795493 [ sid 3 start 1338.52968641 ] clnt 1 srv 2(0) #pages: 1 #objects: 2 total: 4977B seconds: 0.56826852 SUCCESS
1421.11860574 [ sid 4 start 1345.75319688 ] clnt 1 srv 2(0) #pages: 3 #objects: 6 total: 25174B seconds: 75.36540886 SUCCESS
1559.72102735 [ sid 5 start 1530.85835094 ] clnt 1 srv 2(0) #pages: 2 #objects: 3 total: 9565B seconds: 28.86267641 SUCCESS
1762.46745924 [ sid 6 start 1591.87139928 ] clnt 1 srv 2(0) #pages: 3 #objects: 3 total: 9898B seconds: 170.59605996 SUCCESS
2020.12789558 [ sid 7 start 1822.41333981 ] clnt 1 srv 2(0) #pages: 6 #objects: 9 total: 61346B seconds: 197.71455577 SUCCESS
2348.85181273 [ sid 8 start 2067.45385462 ] clnt 1 srv 2(0) #pages: 7 #objects: 14 total: 69341B seconds: 281.39795811 SUCCESS
2492.52192579 [ sid 9 start 2492.49153171 ] clnt 1 srv 2(0) #pages: 1 #objects: 1 total: 2606B seconds: 0.03039408 SUCCESS
2590.15405846 [ sid 10 start 2528.44871353 ] clnt 1 srv 2(0) #pages: 3 #objects: 5 total: 36481B seconds: 61.70534493 SUCCESS
2631.19590927 [ sid 11 start 2593.40280719 ] clnt 1 srv 2(0) #pages: 2 #objects: 4 total: 14987B seconds: 37.79310208 SUCCESS
2768.67779732 [ sid 12 start 2708.89820375 ] clnt 1 srv 2(0) #pages: 3 #objects: 3 total: 17770B seconds: 59.77959357 SUCCESS
3037.57726869 [ sid 13 start 2854.45071944 ] clnt 1 srv 2(0) #pages: 5 #objects: 9 total: 33623B seconds: 183.12654925 SUCCESS
3212.22081067 [ sid 14 start 3132.34843616 ] clnt 1 srv 2(0) #pages: 3 #objects: 3 total: 15702B seconds: 79.87237451 SUCCESS
I made a few regexs to parse the required data from this output like the start time, end time, bytes transferred etc etc. But then I’ll save it for the next post where I’ll deal with it at length and talk about what this post is supposed to be about i.e. gnuplot.
gnuplot is really a versatile tool for plotting both 2D graphs and 3D surfaces. It comes with a very small syntax set that is easy to get hang of once you start using it. I first installed it from the repos without checking the version. So even though the current stable version is v4.2.3 , the repos had v4.0 without any patches. I decided to chuck it and rather build from source. It was a real pain. I spent two hours on getting the right configuration to have the X Windows system support installed. Tried quite a lot of flags with –with-x being included every time but still it was configured without the X windows system support. In the mean time I was being helped by a certain user on #gnuplot. I was about to give it up for the day but then we had a discussion about the possibility of X11 library paths being fucked up in ubuntu. So I decided to configure with the following flags:
$./configure --with-x --with-x-includes=/usr/include/X11 --with-x-libraries=/usr/lib/X11 --with-readline=gnu
..and it was done!
There are different kinds of 2D plots in gnuplot, like lines, linespoints, points, steps etc. I was looking for something that would give me something like a bar chart for the time intervals of the different sessions. So I went for the boxes. The tricky part in plotting with boxes is that you can specify the width of each box in a separate column but the box is drawn centred around the x-axis values. This had me confused for some time before I read the help topic on boxes. So I made a minor change in my program that would put the midpoint of the interval for the x-axis values. The graph looks something like this:

Resources:
1. The demo directory in the source code. Minimal online explanation here.
2. Collection of gnuplot tutorials






