0

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.

1
  • 3
    You've been a member of StackOverflow for more than a year. So, you probably should know that people here expect a minimum of own research effort, i.e. show some code (which doesn't necessarily work). That's probably why somebody downvoted and wanted to close your question because of missing clarity. I find your goal rather clear and there is a solution. See my answer. Commented Dec 30, 2020 at 6:14

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.