1

My data is a typical CSV-like text where each line consists of two columns where the first is text and the second a unix timestamp, as follows:

Mom 1441008169
Dad 1442516527
Ken 1441783871
...
<text> <unix-timestamp>

I thought I could arrange the data along a timeline, drawing dots/shapes of color corresponding to the text in the line, at a point along the x axis corresponding to the timestamp. At best I got gnuplot to tell me:

line 0: Need using spec for y time data

when I tell it to:

set ydata time
set timefmt "%s"
plot "-"
<data>
EOF

I want to render a plot using dots, or diamonds or shapes with color corresponding to the text string in first column. In other words, if my text values fall within the set {"Mom", "Dad", "Ken"}, then gnuplot should draw these shapes corresponding to "Mom" in red, "Dad" in green, and "Ken" in blue, or something like that, at points corresponding to their respective timestamps along the x axis.

The challenge for me is to have gnuplot distinguish between the text strings. The data can be thought of as, for instance, incoming calls from a person where the timestamp indicates date and time for the call and text represents the person calling. I thought representing these data as plotted dots/orbs/diamonds/whatever of different color along a time line would be a good idea, visually.

How would I achieve that? I can, optionally, generate some sort of identifier table where the unique text strings are each equated to a unique sequential generated ID, if that helps gnuplot.

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
  • Not wanting to dissuade you overmuch, having spent many long hours in gnuplot, are you committed to that package? you will find much more flexibility in something more modern and widely contributed to, say pyplot. – Shawn Mehan Oct 29 '15 at 22:40
  • 3
    I like `gnuplot` because it is easily scriptable by piping data to its standard input. At this point I am not considering anything else, but if gnuplot is simply not up to the task, I would have to, of course. – Armen Michaeli Oct 29 '15 at 22:43
  • Regarding the error, see http://stackoverflow.com/q/18118186/2604213 – Christoph Oct 30 '15 at 05:38

1 Answers1

2

I guess what you want is something like this enter image description here

The x-axis spans the time interval which is specified by your data file (2nd column). Each name (Ken, Mom, Dad) is represented by a different point type (pt) and a specific colour (lc rgb 'color').

You can generate this plot by the following commands (assuming your data file's name is 'test'):

set xdata time
set timefmt "%s"
set format x "%d/%m/%y"
set xtics rotate
unset ytics
set yrange[0:2]

plot 'test' u ($2):(stringcolumn(1) eq "Ken" ? 1 :1/0) w p pt 5 ps 1.5 lc rgb 'blue' t 'Ken',\
    '' u ($2):(stringcolumn(1) eq "Dad" ? 1 :1/0) w p pt 7 ps 1.5 lc rgb 'red' t 'Dad',\
    '' u ($2):(stringcolumn(1) eq "Mom" ? 1 :1/0) w p pt 3 ps 1.5 lc rgb 'green' t 'Mom'

You can use different point types by assigning different numbers to pt. ps specifies the point size.

Another representation I came up with is the following:enter image description here You can generate it with:

plot 'test' u ($2):(1):(stringcolumn(1)) with labels t '',\
 '' u ($2):(0.95) with impulses t ''

I hope this answers your question, and it is what you were looking for.

F. Knorr
  • 3,045
  • 15
  • 22
  • This is really great, thanks! The first plot was originally sort of what I wanted, but the complexity of its source code, and given how I would have to somehow map names (`Ken`, etc) to numbers in advance, I think I might go for the second plot. Both seem like a good way to visualize the data. – Armen Michaeli Oct 31 '15 at 12:18