1

I want to plot points with individual labels and colors in Gnuplot.

I have a data file a.dat:

###label x y z  
1 244.8 18 6.1  
2 248.0 10.4 7  
3 294.4 6.3 13.7  
4 248.0 7.5 8.92  
5 240.0 3.69 6.61  
6 240.48 3.69 8.92  
7 256 5.7 15.8  
8 256 7 10.6  
9 256 4.1 8.2  
10 256 5.1 12.3  

The following commands work.

splot 'a.dat' using 2:3:4:1 with labels

set palette model RGB defined (0 'black',1 'blue', 2 'green', 3 'red')  
splot 'a.dat' using 2:3:4:($1==3?1:$1==6?2:$1==9?3:0) with points palette

But how can I mix them?

1 Answer 1

2

Assuming I understood your question correctly, do you really need a palette if you just want to set only a few specific colors to a few specific points? You are using two plotting styles with points and with labels you can combine them in one plot command.

Code:

### variable color points
reset session

$Data <<EOD
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
EOD

myColor(col) = column(col)==3 ? 0x0000ff : \
               column(col)==6 ? 0x00ff00 : \
               column(col)==9 ? 0xff0000 : 0

set key noautotitle
               
splot $Data u 2:3:4:(myColor(1)) w p pt 7 lc rgb var, \
         '' u 2:3:4:1 w labels offset 0.0,0.7,0.7
### end of code

Result:

enter image description here

Addition: (colored labels)

If you want to have colored labels then change the plot command as follows:

splot $Data u 2:3:4:1:(myColor(1)) w labels tc rgb var

Well, you have to decide:

  • using only labels it might be difficult to locate the exact position of your data point
  • using a point and a label without offset it might be diffcult to read the number

Result: (colored label without point)

enter image description here

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

4 Comments

@IV_ ok, so you wanted colored labels instead of colored points?
I am trying to add a conditional operator on text value of a column, but it is failing. Any thoughts on this please? using 3:4:(sprintf("%g",(($6 eq "Swim") ? (tc lt 4):(tc lt 1)))) with labels
@bonCodigo this is a different topic. Do you want conditional text color or conditional text? Please open a new question with the script you tried and the resulting graph.
conditional text colour. But I also want to how to validate a string/text value in a colum data.

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.