RamboSushi
RamboSushi

Reputation: 89

Using Gnuplot for multiples lines chart

I have a txt file containing the following data:

0 0 0.000004 1 0.000003 2 0.000002 3 0.000002 ... 99 0.000002 100 0.000001

1 0 0.000002 1 0.000002 2 0.000001 3 0.000002 ... 99 0.000021 100 0.000020

2 0 0.000003 1 0.000002 2 0.000003 3 0.000003 ... 99 0.000041 100 0.000044

3 0 0.000003 1 0.000002 2 0.000004 3 0.000004 ... 99 0.000071 100 0.000070

I would like to use this in a gnuplot line chart. The first number of each line defines a color (a group), then in duo, the second and the third define a data pair (single digit on the ordinate, decimal point on the abscissa). Consequently the fourth and fifth are in duet, always with the same color. In the present example, there will therefore be 3 different colors (therefore lines), and 100 points per color. I can get rid of the first digit of each line if needed, and define a newline as a color change (group). I put some data in bold to better see the duos.

Thank you in advance for your help. The commands that I will execute will be on Unix terminal.

Upvotes: 0

Views: 82

Answers (1)

theozh
theozh

Reputation: 26158

Well, your data format is a bit special. And you might know that gnuplot doesn't like data in rows. Fortunately, gnuplot is flexible to also handle this format. Of course, you could always use other tools to re-format your data into a format which is more convenient to read for gnuplot. If possible I prefer to avoid additional external tools to ensure cross-platform compatibility.

Check the keywords help for, help matrix and help every. In the case below matrix every a::b:i::i means: it plots every ath column starting from column b, but only for row i (actually from row i to row i).

Code:

### plot special data format
reset session

# create some test data
set print $Data
do for [i=0:3] {
    Line = sprintf("%d",i)
    do for [j=0:100] {
        Line = Line.sprintf(" %d %.3f", j, rand(0)*0.5+i)
    }
    print Line
}
set print

set key out

plot for [i=0:3] $Data u (column(1)/2-1):3 matrix every 2::2:i::i w lp \
     lc i+1 pt i+4 title sprintf("Serie %d",i)
### end of code

Result:

enter image description here

Upvotes: 1

Related Questions