tags:

views:

196

answers:

2

I need to graph some data that is not exactly in the most friendly format, most examples or usage puts things in a nice column/table that is very easy to parse and graph. However I have the following format (and am a bit stuck as to how to tackle this):

DATE1 label_1 xx yy
DATE1 label_2 xx yy
DATE1 label_3 xx yy

DATE2 label_2 xx yy
DATE2 label_3 xx yy

DATE3 label_1 xx yy
DATE3 label_2 xx yy
DATE3 label_3 xx yy

DATE4 label_2 xx yy
DATE4 label_3 xx yy
...continues

*I've added the extra space between the dates for readability.

**Note: under DATE2,DATE4 label_1 is missing, i.e. the data file may have labels that come and go and should represent a discontinuity in the graph.

I'd like to have the X-axis use the DATEX for the labels, and then create two lines for each label (xx and yy respectively).

Does anyone have any suggestions on the best way to tackle this problem?

+2  A: 

I don't quite get what kind of graph you want to produce. Points are defined by two coordinates, and I can imagine plotting multiple data sets together for comparison, so that would account for three parameters. Where does the fourth fit in? Do you want a clustered histogram?

Anyway, if the data format I get doesn't suit gnuplot, I usually do some preprocessing to produce the data file for gnuplot (using Common Lisp or Perl).

Update: Following your clarifying comment, I would transform the file into this format:

# DATE, label-1-x, label-1-y, label-2-x, label-2-y, label-3-x, label-3-y
     1,        xx,        yy,        xx,        yy,        xx,        yy
     .
     .
     .
Svante
I'm sorry for the confusion. For clarification: the XX per label_* will be one line graph, the YY will be another for label_*. So each label_* will have two line graphs associated with it. In this particular example I will have a total of 6 lines on the graph.
Zack
+1  A: 

Your best bet might just be to a Gunplot.py (http://gnuplot-py.sourceforge.net/) to create a script that will perform the tasks you need. You can then build the plot as you would in gnuplot.

    g = Gnuplot.Gnuplot()
    g('set datafile separator " "')
    plot = "plot "
    plot += "'%s' using 1:3 title '($2)' with lines" % (filename))
    plot += ", '%s' using 1:4 title '($2)' with lines" % (filename))
    g(plot)

If you haven't looked into gnuplot.py already i'd definitely give it a look. There's a mailing list on there too that might be of more specific help.

olan