2

Plotting data of file data.txt from line 1 to 10 in some color say red and next 10 to 20 with other similarly 20 to 30 with different color till 100th row

data.txt file is something like this:

1 1 
2 2
3 3
4 4
5 5
6 6
..
..
..
10 10

1 2
3 4
1 1
..
..
..
..

.
.
.
.

90 90
91 91
..
..
..
100 100
4
  • @GautamSavaliya the problem has just one line answer I plotted all points using same color but need different color for different row range gnuplot "data.txt" Commented May 7, 2016 at 5:46
  • 2
    Can you please try to write in full sentences, with question marks etc.? This is insulting to the reader. Commented May 7, 2016 at 12:51
  • @Karl I was in a hurry. missed question mark. Is question mark important? Commented May 8, 2016 at 9:26
  • 1
    Punctuation is highly important in western languages. The order of words in a sentence changes the meaning completely, so you need to know where it starts and ends. Commented May 8, 2016 at 12:23

3 Answers 3

2

plot 'aaa.txt' every ::1::10 w p, 'aaa.txt' every ::11::20 w p, ...

UPDATE

worked for me (well, except numbering should go from 0)

plot 'aaa.txt' every ::0::2 w p, 'aaa.txt' every ::3::5 w p

produced following graph

enter image description here

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

Comments

1

If you can structure your data-file to separate every data block with 2 empty lines, you can use feature index with a for loop:

unset key
plot for [i=0:9] 'temp.txt' index i

plot in 10-itemed blocks

(my datafile is 1-10 in every block (1-10, 11-20...), structured with 2-2 empty lines)

If you can't structure your data-file (our you are just lazy ;-) ) you can use only the for loop:

plot for [i=0:9] 'temp2.txt' every ::i*10::i*10+9

(my datafile is 1-10 in every block (1-10, 11-20...) without empty lines)


EXTENSION (according to Karl)

If you can structure your data-file to separate every data block with 1 empty lines, you can use feature index with a for loop

plot for [i=0:9] 'temp3.txt' every :::i::i

(my datafile is 1-10 in every block (1-10, 11-20...), structured with 1-1 empty lines)

2 Comments

For a single line between datasets ... every :::i::i (feel free to add to your anwer).
thanks, but your extension above makes no sense as it is now
0

In addition to @TomSolid's answer with a for loop and every, I guess there is even a simpler version.

If there is exactly one empty line between the data(sub)blocks, you can use the pseudocolumn -1 (check help pseudocolumns) together with linecolor variable (check help colorspec).

plot $Data u 1:2:-1 w l lc var

However, since the default line colors will repeat in cycles of 8 you could instead define your own function using pseudocolumn -1 as argument.

Script:

### line color depending on subblock
reset session

# create some random test data
set table $Data
    set samples 110
    plot y0=0 '+' u (c=int($0),c%11?c-c/11:''):(c%11?y0=y0+rand(0)-0.5:'') w table
unset table

myColors     = "0xff0000 0x00ff00 0x0000ff 0xff00ff 0xffff00 0x00ffff \
                0xcc0000 0x00aa00 0x0000aa 0xcc00aa 0xccaa00 0x00aacc"
myColor(col) = int(word(myColors, int(column(col))%words(myColors)+1))

plot $Data u 1:2:(myColor(-1)) w l lw 2 lc rgb var notitle
### end of script

Result:

enter image description here

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.