Alibaba seeks $2.3B from shareholders for Yahoo deal http://t.co/ySyCwLvJ via @zdnetasia
8 minutes ago by arbastaki on twitter
ZDNet is available in the following editions:
Marco Fioretti explains how you can use Gnuplot to make handy charts of time-based data and offers some tips for making it generate what you want.
figure figure, marco fioretti, linux, computer technology, open source software, science and technology, software, technology
Gnuplot is, in my opinion, one of the best open source tools to plot charts on Linux. I like it because:
In other words, I like Gnuplot because it makes automatic chart creation as easy as possible: you can generate both data and Gnuplot commands on the fly with whatever program or programming language you like best, and then pass them to Gnuplot.
With the exception (unless you adopt some tricks) of pie charts, Gnuplot can plot practically every kind of diagram... if you know which options to use. Here I will explain in detail only the little known ones that let Gnuplot recognize certain strings as absolutes dates or hours and, consequently, properly plot time-related data.
Let's assume that you have a data file ("datafile.dat") like this:
20110101 30
20110108 21
20110115 28
20110122 3
20110129 6
20110205 9
20110212 12
20110219 25
20110226 22
20110305 18
20110312 37
20110319 37
20110326 32
20110402 41
20110409 35
20110416 26
20110423 27
20110430 20
A human would understand immediately that the numbers in the first columns are, very likely, dates. Gnuplot, instead, won't. Not by itself, at least. If you just tell it to plot the file with these instructions:
 set terminal png size 900, 300 set output "chart_1.png" plot [:][:] 'datafile.dat' using 1:2 title "This is what you get when gnuplot doesn't recognize time values" with lines
that is, using the first column for the X axis and the second for the Y one, you'll get the chart of Figure A: "20110101″ isn't recognized as "January 1st, 2011″ but as "twenty millions something..." Really ugly and unreadable, isn't it?
The solution is to set the xdata and timefmt variables of Gnuplot, by adding these commands right before the plot instruction:
 set xdata time set timefmt "%Y%m%d"
The first one tells Gnuplot that the numbers that go on the X axis are time values. The second explains how they are formatted. In our example, the format is YYYYMMDD, but it could have many other values, all described in the documentation (more on this later).
In practice, there are only two constraints here. The first is that only one time/date input format per plot is supported. The other is that, to let Gnuplot handle without problems times values containing spaces, e.g., "2011/06/02 11:18″, the columns in the data file must be separated by tabs instead of spaces when such strings are present.
Back to plotting now. Run Gnuplot with the latest settings and lo! the numbers of the first column will be recognized for what they are and printed accordingly, as in Figure B.
Much better now, isn't it? We can make it even better, however. Luckily, the way the time values are formatted in the data file and the way in which they will be printed in the plot are completely independent. The timefmt variable that we've already seen specifies how to read the time column in the data file.
Timefmt recognizes lots of formats: %j, for example, indicates the day of the year in the 1- 365 format, and %B the month name (in English!). To read about all the capabilities of timefmt, type gnuplot in a terminal and then help set timefmt.
The other thing you need to know in order to plot readable time-based charts is how to plot ranges and display tics on the time axis to show just what you, not Gnuplot, think is relevant.
If you only want to plot a certain range of values from the data file, specify it by setting the xrange with the same format used by timefmt, that is the one in the original data file:
 set xrange ["20110402":"20110430"]
This is how to plot "restricted" chart like the one of Figure C.
Settings number, positions and names of the tics is a bit more complicated, but not so much. The names are set either by listing them explicitly, or assigning a format to the xtics variable. This, for example:
  set xtics format "%b %d"
means that Gnuplot should use the abbreviated month name (%b) and day of the month (/%d) to print tics like "Jan 20″, "Mar 11″ and so on. Position and number of tics can be controlled in several ways. The most flexible one is to assign to xtics a start and end value, plus the number of seconds between two consecutive tics.
Let's assume, for example, that we want to display one tic every two weeks, on Wednesdays. Since the first Wednesday of 2011 was January 5th and there are 60×60x24×7x2 = 1209600 seconds in two weeks, here's how to plot what you see in Figure D:
 set grid set xtics format "%b %d" set xtics "20110105", 1209600, "20110430"
Cool, right? Please note that "set grid" wasn't necessary; it just makes it easier to see that the tics appear just where they should. The only gotcha here is to remember that you must specify start and end tics in the format in which they appear in the source file ("20110105"), not the one shown in the plot ("Jan 05").
Summing up
Charts of time-based data are extremely useful, in many ways, for work and study. Here I have explained all you'll probably need to know to use Gnuplot to make sense of such data. In case it isn't enough, you can find even more information in the Gnuplot documentation by typing help time/date or help set xtics at the prompt.
Marco Fioretti is a freelance writer and teacher whose work focuses on open digital technologies.
Alibaba seeks $2.3B from shareholders for Yahoo deal http://t.co/ySyCwLvJ via @zdnetasia
8 minutes ago by arbastaki on twitterRise in Chinese-funded acquisitions could trigger more hurdles: By Ellyne Phneah , ZDNet Asia on May 22, 2012 (6... http://t.co/L4QzDq3H
37 minutes ago by LocalMobile911 on twitterKodak loses patent ruling against Apple, RIM - ZDNet Asia http://t.co/O7P8U2Ya
37 minutes ago by PatentWire on twitterRise in Chinese-funded acquisitions could trigger more hurdles - ZDNet Asia http://t.co/WJCfhWLs
38 minutes ago by JapanTechnology on twitterKodak loses patent ruling against Apple, RIM. http://t.co/N1j7aZ6o
53 minutes ago by zdnetasia on twitterRise in <b>Chinese</b>-funded acquisitions could trigger more hurdles http://t.co/0pXBS1HR
1 hour ago by GeorgeHAllenGA on twitterRise in Chinese-funded acquisitions could trigger more hurdles: By Ellyne Phneah , ZDNet Asia on May 22, 2012 (6... http://t.co/W3SOdw2c
1 hour ago by MergeAcquire on twitterRT @zdnetasia: CFOs increasingly involved in IT investment decisions. http://t.co/8QrfwOSb
1 hour ago by 666hellscream on twitterCFOs increasingly involved in IT investment decisions http://t.co/XD1LerFq via @zdnetasia #PrivateCloud #SC2012 #CAPEX
2 hours ago by HarishAitharaju on twitterRise in Chinese-funded acquisitions could trigger more hurdles. http://t.co/VC3G3m3o
2 hours ago by zdnetasia on twitterRT @zdnetasia: Rise in Chinese-funded acquisitions could trigger more hurdles. http://t.co/VC3G3m3o
2 hours ago by wrikent3500 on twitterSo much as we know , MTK6575 extremely integrated frequency1GHz ARM Cortex-A9 processor, the superiority of 3G / HSPA Modem, and help the...
2 hours ago by y15822137359 on 5 SaaS adoption speed bumps to avoidRise in Chinese-funded acquisitions could trigger more hurdles - ZDNet Asia: Rise in Chinese-funded acquisitions... http://t.co/bZaAQnRL
2 hours ago by MandAWorldwide on twitterRise in Chinese-funded acquisitions could trigger more hurdles http://t.co/mIsuZjnU http://t.co/erFX4aVv #arcavir
2 hours ago by V_RaV on twitterhttp://t.co/VNaZtseV Rise in Chinese-funded acquisitions could trigger more hurdles: "Cash r... http://t.co/N0gZZEdR http://t.co/wiqY9ktt
2 hours ago by RavtachSolution on twitterI reckon your view: "CRM is strategy, not software", if a company replicating the approach uses in ERP implementation into CRM, what they...
1 day ago by wykoong on Gartner: Mobile CRM gives better ROI than socialThis video will teach you about the Excel fill handle but also provide you with a workook to download... http://www.youtube.com/watch?v=...
1 day ago by TradeBrother on A quick fill handle trick for Microsoft Excelwaiting...
3 days ago by eapete on What should count in a company's market value?Boy, you've opened a can of worms now.
Wait for the rants & raves.
I was puzzling before this whether to replicate the success formula we executed for a financial institute, and come out with a standard s...
4 days ago by wykoong on Drop the egos, copy ideas, then innovateEchelon 2012 - The Awesomer Tech Event in Asia
Echelon 2012 – SEA’s longest running tech startup event goes Awesomer. Catch 50 of Asia’s most promising startups & over 40 international speakers on June 11-12.
Startup Asia Jakarta showcases new product-ready tech startups. Plus: hackathon, exhibition, and speakers. Use promo code CBSi50 for 50% discount.
ZDNet Asia Intelligent Singapore video series
Featuring inteviews with CXOs who define "intelligence" in their markets and reveal how their companies drive business efficiencies through ICT.