{"id":761,"date":"2011-09-02T17:05:36","date_gmt":"2011-09-02T16:05:36","guid":{"rendered":"http:\/\/blogs.oucs.ox.ac.uk\/networks\/?p=761"},"modified":"2011-09-02T17:05:36","modified_gmt":"2011-09-02T16:05:36","slug":"how-to-generate-graphs-with-gnuplot","status":"publish","type":"post","link":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/2011\/09\/02\/how-to-generate-graphs-with-gnuplot\/","title":{"rendered":"How to generate graphs with gnuplot"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>During the JANET Carrrier Ethernet Trial we we took part in, I needed to plot some data based on our testing and came across gnuplot. It is actually quite simple to use and we&#8217;re doing so more and more so I thought I share some of what I&#8217;ve learned.<\/p>\n<h3>Process<\/h3>\n<p>First you need to generate a text file of data which you wish to graph (whitespace is fine as a delimiter).<\/p>\n<p>Here is a sample of some data I created. It is the number of unique users of OWL Visitor (our guest wireless service) per day:<\/p>\n<pre>2011-08-17 670\r\n2011-08-18 666\r\n2011-08-19 619\r\n2011-08-20 470\r\n2011-08-21 368<\/pre>\n<p>Install gnuplog on the server you are using. At the time of writing it available natively in RedHat and Debian. You need to generate a config file,\u00a0<code># man gnuplot<\/code> is your friend here.<\/p>\n<pre># gnuplot script file for plotting bandwidth over time\r\n#!\/usr\/bin\/gnuplot\r\nreset\r\nset terminal png\r\n\r\nset xdata time\r\nset timefmt \"%Y-%m-%dT%H:%M:%S\"\r\nset format x \"%d\/%m\"\r\n\r\nset xlabel \"Date (day\/month)\"\r\nset ylabel \"Number of uniqe visitor users\"\r\n\r\nset title \"Visitor Users over time\"\r\nset key below\r\nset grid\r\n\r\nplot \"\/home\/networks\/unique_visitors.csv\" using 1:2 title \"Visitors\"<\/pre>\n<p>Hopefully the config file above is fairly self explanatory. To generate the graph simply run the following:<\/p>\n<pre>\/usr\/bin\/gnuplot visitor_users.gp &gt; \/home\/networks\/visitor_users.png<\/pre>\n<p>Where visitor_users.gp is the name of the config file above. Here is the result, using a larger dataset:<\/p>\n<p><a href=\"http:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/visitors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-764\" src=\"http:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/visitors.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/visitors.png 640w, https:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/visitors-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>You can then use a cronjob to update the data and replot the graph regularly.<\/p>\n<h3>Using variables in the config file<\/h3>\n<p>If you would like to manipulate the data you are plotting on the fly, for example to scale something down, you can. An example is probably best here.<\/p>\n<p>Here is a small subset of the data:<\/p>\n<pre>2011-08-01T09:10:03 31106 630881 15746233 27439 609104 15924148 128 8133029 32533776\r\n2011-08-01T09:20:04 31106 630929 15747201 27439 609152 15925609 128 8133029 32533776\r\n2011-08-01T09:30:03 31106 631020 15750202 27447 609203 15928230 128 8144560 32584722\r\n2011-08-01T09:40:03 31106 631078 15751874 27453 609238 15930112 128 8144560 32584722\r\n2011-08-01T10:00:03 31110 631196 15754712 27455 609310 15933583 128 112198088 40867109\r\n2011-08-01T10:10:03 31115 631354 15760272 27455 609333 15935724 128 112203231 40895646\r\n2011-08-01T10:20:02 31117 631425 15763701 27460 609471 15941256 128 112203231 40895646\r\n2011-08-01T10:30:03 31121 631558 15766657 27461 609489 15943780 128 112204920 40903491<\/pre>\n<p>and the config:<\/p>\n<pre>#!\/usr\/bin\/gnuplot\r\nreset\r\nset terminal png\r\n\r\nset xdata time\r\nset timefmt \"%Y-%m-%dT%H:%M:%S\"\r\nset format x \"%d\/%m\"\r\n\r\nset xlabel \"Date (day\/month)\"\r\nset ylabel \"Number of NP Blocks \/ 10000\"\r\n# set ylabel \"Number of NP Blocks \/ 10000 (log)\"\r\n# set log y\r\n\r\nset title \"NP Blocks over time\"\r\nset key below\r\nset grid\r\n\r\nplot \"\/home\/netdisco\/np-blocks.csv\" using 1:($2\/10000) title \"NP1_0\" , \\\r\n\"\" using 1:($3\/10000) title \"NP1_1\", \\\r\n\"\" using 1:($4\/10000) title \"NP1_2\", \\\r\n\"\" using 1:($5\/10000) title \"NP2_0\", \\\r\n\"\" using 1:($6\/10000) title \"NP2_1\", \\\r\n\"\" using 1:($7\/10000) title \"NP2_2\", \\\r\n\"\" using 1:($8\/10000) title \"NP3_0\", \\\r\n\"\" using 1:($9\/10000) title \"NP3_1\", \\\r\n\"\" using 1:($10\/10000) title \"NP3_2\"<\/pre>\n<p>Again, here is the result:<\/p>\n<p><a href=\"http:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/np-blocks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-765\" src=\"http:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/np-blocks.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/np-blocks.png 640w, https:\/\/blogs-new.it.ox.ac.uk\/networks\/files\/2011\/09\/np-blocks-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Hopefully that has been a useful primer on gnuplot, happy graphing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction During the JANET Carrrier Ethernet Trial we we took part in, I needed to plot some data based on our testing and came across gnuplot. It is actually quite simple to use and we&#8217;re doing so more and more &hellip; <a href=\"https:\/\/blogs-new.it.ox.ac.uk\/networks\/2011\/09\/02\/how-to-generate-graphs-with-gnuplot\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":12,"featured_media":764,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[278,354,13463,12],"tags":[],"class_list":["post-761","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-documentation","category-productivity","category-trend-analysis","category-wireless"],"_links":{"self":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/comments?post=761"}],"version-history":[{"count":5,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":769,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/posts\/761\/revisions\/769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/media\/764"}],"wp:attachment":[{"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/media?parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/categories?post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs-new.it.ox.ac.uk\/networks\/wp-json\/wp\/v2\/tags?post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}