I have a data points file which contains
1 0 0
0 2 0
0 0 3
Then I wrote this code (snippet) to draw a variable size points for 1 or 2 or 3
xcoord(N) = (N)
ycoord(N) = (column(0)+1)
symbol(N) = strcol(N) eq "3" ? 3 : ( strcol(N) eq "2" ? 2 : (strcol(N) eq "1" ? 1 : 0) )
set xtics ("2000" 2, "2001" 3, "2002" 4)
set ytics ("M1" 1, "M2" 2, "M3" 3)
plot for [N=1:3] 'data.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)*1) with points pt 7 ps var
Problem is all points have the same color. I want to use different colors for 1, 2 and 3. How can I do that?
Use linecolor variable to select a line type (or line style) based on a data column, see the two recent questions Gnuplot: Data blocks with different colours and Gnuplot with both color and xtic from data file
I'm not really sure, what the end result should be, but your example looks a bit strange. Why do you read the data as string and then convert it back to a number?
Just use
set offset 0.1,0.1,0.1,0.1
plot 'data.txt' matrix using 1:2:3:3 lc var ps var pt 7

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With