开发者

How can I use gnuplot to plot data that is in an un-friendly format?

开发者 https://www.devze.com 2022-12-28 19:55 出处:网络
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

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 respecti开发者_运维百科vely).

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


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.


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
     .
     .
     .
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号