2

I should like to gnuplot some data for various devices, where the data is the time those devices are in a certain state.

For example, given devices a to e, plot the time they go into alarm then exit, e.g. device a goes into alarm 11:00, out of alarm at 12:00, etc..

dev_a |   x------x
dev_b |     x-----x
dev_c | x-x
dev_d |           x-------------------
dev_e |     x-----x       x-----x
      |_______________________________
          |      |     |     |     |
        11:00  12:00 13:00 14:00 15:00

The input data would would need to be derived from logs similar to:

    ....
11:00 dev_a alarm on
    ....
11:00 dev_c alarm off
11:10 dev_b alarm on
    ....
12:00 dev_a alarm off
    ....

I am not really sure how to get started—a column plot of sorts?

Svante
  • 50,694
  • 11
  • 78
  • 122
hanlonj
  • 319
  • 4
  • 16
  • You might have a look at http://stackoverflow.com/questions/7684475/plotting-labeled-intervals-in-matplotlib-gnuplot – XTL May 30 '12 at 07:31

2 Answers2

2

To get started, you should adjust your input file to:

11:00 1 dev_a alarm on
11:01 3 dev_c alarm off
11:10 2 dev_b alarm on
12:00 1 dev_a alarm off
12:10 2 dev_b alarm on
11:15 4 dev_d alarm on
11:25 4 dev_d alarm off

then you use

set xdata time
set timefmt "%H:%M"
plot "file.txt" using 1:2:ytic(3) with points

You need the second column to put all entries of alarm a on 1 y axis label.

This will give you almost what you want. The only thing that is missing are the lines between the points. A possibility is to use arrows (without the head of the arrow so in fact it is a line) and build a script file in order to plot all arrows at once. Check out the answer of Tom with this question for a nice example: Plotting arrows with gnuplot

Community
  • 1
  • 1
Martin
  • 1,084
  • 9
  • 15
1

If you somehow manage to convert and split your log files into some format like this:

#time  dev_a
11:00   1
12:00   1
#time  dev_b
11:10  2
12:10  2

...

That is time format into floats, separate files per device, alarm on/off to const dev_id. Plotting becomes easy:

set style data linespoints
set yrange [0:5]
set xdata time
set timefmt "%H:%M"
plot "dev_a.data" using 1:2 title "dev_a", "dev_b.data" using 1:2 title "dev_b", ...

Ok, y-axis description is still an issue, but you can combine that with Martins answer.

LumpN
  • 66
  • 1
  • Not a bad idea, but it would require a separate file for each on/off cycle for each device, so as long as that does not happen a lot of times it is fine. – Martin Jan 31 '11 at 11:38
  • trying to massage the logs now and to try out suggestions. however, lumpns point is correct each device will go into/out of alarm often - didnt think to point this out. example hourly plot is for simplicity, actual would be to second resolution with high frequency. separate data files for each alarm high would be impractical. – hanlonj Jan 31 '11 at 12:37
  • just to clarify, how many data files would dev_e require? 1 or 2 – hanlonj Jan 31 '11 at 13:00
  • dev_e in your sketch of the plot would require 2 files, 1 file for each alarm_on alarm_off – Martin Jan 31 '11 at 13:27