damned
damned

Reputation: 945

Multiple plots with gnuplot by grouping columns

I have a data file with schema as "object parameter output1 output2 ...... outputk". For eg.

A 0.1 0.2 0.43 0.81 0.60
A 0.2 0.1 0.42 0.83 0.62
A 0.3 0.5 0.48 0.84 0.65
B 0.1 0.1 0.42 0.83 0.62
B 0.2 0.1 0.82 0.93 0.61
B 0.3 0.5 0.48 0.34 0.15
...

I want to create multiple plots, each plot corresponding to an object, with x axis being the parameter and series being the outputs. Currently, I've written a python script which dumps the rows for each object in different files and then calls gnuplot. Is there a more elegant way to plot it?

Upvotes: 0

Views: 303

Answers (1)

ztik
ztik

Reputation: 3612

You are looking for this:

plot 'data.txt' using (strcol(1) eq "A" ? $2 : 1/0):4 with line

which results to: enter image description here

If you would like to create plots for every object use:

do for [object in "A B"] {
  reset
  set title sprintf("Object %s",object)
  plot 'data.txt' using (strcol(1) eq object ? $2 : 1/0):4 notitle with line
  pause -1
}

Just press Enter for next plot. Of course you can export these plots in files, too.

Upvotes: 0

Related Questions