Calculation using multiple variables in gnuplot

I have a data file with multiple columns, the first two indicate a position and the rest indicate other properties (like the number of items sent from that point). eg:

1  1  1  57.11
2  1  2  62.40
3  4  1  31.92

      

What I want to do is draw points at positions, but use values ​​from other columns to change the point type and size (for example). However, I cannot find a way to reference the columns in the plot. I am aware of using "variable", but I cannot find a way to use multiple variables.

I want something like the following:

plot "mydata" using 1:2 notitle with points pt ($3) ps ($4/10)

      

so pt and ps use the value for each point taken from the third and fourth columns, respectively.

Is this possible in gnuplot? Is there a job?

+3


source to share


1 answer


You can use a keyword variable

to do something like this:

plot 'datafile' using 1:2:3:4 w points ps variable lc variable

      

Or perhaps mapping a value to a palette:

plot 'datafile' using 1:2:3:4 w points ps variable lc palette

      

The keyword and / or palette variable causes gnuplot to read properties from a file, and these require an extra column to read through using

. Of course, all the usual things with use apply - you can apply transformations to data, etc .:

plot 'datafile' using 1:2:3:($4+32.) w points ps variable lc palette

      


I don't remember, from my point of view, if the third column is going to be an area or a color here, and I don't have time right now to play with it to figure it out. You can do an experiment and post a comment, or I'll come back to this when I have time and add an update.




Some other properties (for example pointtype

) cannot be easily changed with variable

. The easiest way to do this is to use filters with the gnuplot ternary operator.

First, write a function that returns a point type based on data from 1 column of the data file:

my_point_type(x) = x   

      

I am using a simple identification function here, but it could be anything. Now you can iterate over the type you want (here 1-10), plotting for each:

plot [for PT=1:10] 'datafile' u 1:((my_point_type($3) == PT) ? $2:NaN) with points pt PT

      

It is assumed that the type information column indicates the third column and the second column contains the location information. It can also be combined with the material I demonstrated above.

+4


source







All Articles