Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot read line style from data file column

Tags:

gnuplot

I'd like to draw an impulse graph from a text file that looks like this:

II 5 0 0 288.40 1.3033e+14 
II 6 0 0 289.60 1.5621e+14 
II 1 4 0 302.70 3.0084e+13 
II 2 4 0 303.40 4.0230e+13 
II 1 5 1 304.40 3.4089e+13

The plot conceptually should be plot "datafile.dat" using 5:6 w impulses ls $2.

Basically, given a previously defined set of line styles, I'd like to input the line style number from column 2 for every couple of plotted points from column 5 and 6.
Also I'd like to create a text box, for every plotted point, taking strings from the first four columns.

Does somebody know if that's possible?

like image 785
user3442072 Avatar asked Mar 20 '23 04:03

user3442072


2 Answers

To use the data from column two as line style use set style increment user and linecolor variable:

set style increment user
plot "datafile.dat" using 5:6:2 with impulses lc var

In order to place a label, use the labels plotting style:

plot "datafile.dat" using 5:6:1 with labels offset 0,1

Putting everything together, you have:

set style increment user
set for [i=1:6] style line i lt i
set yrange [0:*]
set offsets 0,0,graph 0.1,0
plot "datafile.dat" using 5:6:2 with impulses lc var, "" using 5:6:1 with labels offset 0,1

The result with 4.6.3 is:

enter image description here

like image 52
Christoph Avatar answered Mar 29 '23 00:03

Christoph


Thanks for the helpful answer above. It almost solved my problem

I'm actually trying to use a column from my data file to specify a linestyle (dot, squares,triangles, whatever as long as it's user-defined), and not a linecolor. Is there any way to do that?

This line works : I get points with different colors (specified in column 4), but the point style is the same.

plot "$file" u 1:2:4 w p notitle lc var, "" using 1:2:3 with labels offset 0,1 notitle

Replacing lc with ls after defining my own styles doesn't work (ls can't have variable as an option) I can live without different linestyles, but it would be much prettier.

like image 43
SOKS Avatar answered Mar 29 '23 00:03

SOKS