1

I have a two colum txt file and I plot the data as below

MyColor(n) = n==0 ? 0x008000  : n==1 ? 0xFF0000 : n==2 ? 0x000000 : 0xFF8C00
plot datafile u 1:2:(MyColor(column(-2))) w l  lw 1.0 lc rgb   var notitle

This gives me bottom three lines in three different colour and others in the same colour (0xFF8C00), Left figure. But I want to plot only upto n==2 (there will be only three lines in the plot) and other row with 0xFF8C00 should not be in the plot and for each n (n==0 ? 0x008000 : n==1 ? 0xFF0000 : n==2 ? 0x000000) and I want to label a name with each colour as shown in right side figure. enter image description here

5
  • Take a look at help every and help label. Commented Jun 1, 2020 at 1:39
  • Thank you very much Sir. For simple file it worked well (help every) but for a file like , please download from here with replacing XXXX with https:// (XXXXwe.tl/t-5SFzfiKwjb ) it is working on segments along X-axis. Commented Jun 1, 2020 at 4:55
  • the link is not valid anymore... Commented Jul 1, 2020 at 17:46
  • Yes, it was for seven days. I will update it. I am trapped in COVID-19 issue and can not work more. Thank you sir for your have a look on my post. I see your another reply that I will also update after some time. Commented Jul 1, 2020 at 17:49
  • I guess it's fine, I don't need the data anymore. Check my answer. Commented Jul 1, 2020 at 19:06

1 Answer 1

1

If I interpret your question correctly, I guess you are looking for index and label. Check help index and help label. There might be a bit confusion about every and index.

  • every allows selecting "blocks" which are separated by one empty line.
  • index allows selecting "blocks" which are separated by two or more empty lines.

Code:

### plot only selected block
reset session

# create some test data
set print $Data
do for [i=1:7] {
    do for [j=1:100] {
        print sprintf("%.3f %.3f", j, sin(j/30.)+i*0.2 + 0.05*rand(0))
    }
    print ""; print ""    # two empty lines
}
set print

myColor(n) = n==0 ? 0x008000  : n==1 ? 0xFF0000 : n==2 ? 0x000000 : 0xFF8C00

set label 1 "LA" at 40, 1.3 tc rgb myColor(0)
set label 2 "ZA" at 30, 1.4 tc rgb myColor(1)
set label 3 "TA" at 67, 1.5 tc rgb myColor(2)

plot $Data u 1:2:(myColor(column(-2))) index 0:2 w l lw 1.0 lc rgb var notitle
### 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.