0

I have data in the format:

1  1  A
2  3  ab
1  2  A
3  3  x
4  1  x
2  3  A

and so on. The third column indicates the series. That is in the case above there are 3 distinct data series, one designated A, another designated ab and last designated x. Is there a way to plot the three data series from such data structure in gnuplot without using eg. awk? The difficulty here is that the number of categories (here denoted A, ab, x) is quite large and it is not feasible to write them out by hand. I was thinking along the lines:

plot data u 1:2:3 w dots

but that does not work and I get warning: Skipping data file with no valid points (I tried quoted and unquoted version of the third column). A similar question has to manually define the palette which is undesirable.

atapaka
  • 1,172
  • 4
  • 14
  • 30

1 Answers1

0

With a little bit of work you can make a list of unique categories from within gnuplot without using external tools. The following code snippet first assembles a list of the entire third column of the data file, and then loops over it to generate a list of unique category names. If memory use or processing time become an issue then one could probably combine these steps and avoid forming a single string with the entire third column.

delimiter = "#"    # some character that does not appear in category name
categories = ""

stats "test.dat" using (categories = categories." ".delimiter.strcol(3).delimiter) nooutput

unique_categories = ""
do for [cat in categories] {
   if (strstrt (unique_categories, cat) ==0) {
      unique_categories = unique_categories." ".cat
   }
}

set xrange[0:5]
set yrange [0:4]
plot for [cat in unique_categories] "test.dat" using 1:(delimiter.strcol(3).delimiter eq cat ? $2 : NaN) title cat[2:strlen(cat)-1]

enter image description here

Take a look at the contents of the string variables categories and unique_categories to get a better idea of what this code does.

user8153
  • 4,049
  • 1
  • 9
  • 18