4
votes

I have x,y values for points in the first 2 colums and a number that indicates the point type (symbol) in the 3. column, in one data file. How do I plot data points with different symbols?

2

2 Answers

4
votes

Unfortunately, there isn't a way (AFAIK) to automatically set the point of the plot from a column value using vanilla GNUPLOT.

However, there is a way to get around that by setting a linestyle for each data series, and then plotting the values based on that defined style:

set style line 1 lc rgb 'red' pt 7 #Circle
set style line 2 lc rgb 'blue' pt 5 #Square 

Remember that the number after pt is the point-type.

Then, all you have to do is plot (assuming that the data in "data.txt" is ordered ColX ColY Col3):

plot  "data.txt" using 1:2 title 'Y Axis' with points ls 1, \
"data.txt" using 1:3 title 'Y Axis' with points ls 2

Try it here using this data (in the section titled "Data" - also note that column 3 "Symbol" is noted used, it's mainly there for illustrative purposes):

# This file is called   force.dat
# Force-Deflection data for a beam and a bar
# Deflection    Col-Force       Symbol 
0.000              0              5
0.001            104             5
0.002            202            7
0.003            298            7

And in the Plot Script Heading:

set key inside bottom right
set xlabel 'Deflection (m)'
set ylabel 'Force (kN)'
set title 'Some Data'
set style line 1 lc rgb 'red' pt 7
set style line 2 lc rgb 'blue' pt 5
plot  "data.txt" using 1:2 title 'Col-Force' with points ls 1, \
"data.txt" using 1:3 title 'Beam-Force' with points ls 2

The one caveat is of course that you have have to reconfigure your data input source.

REFERENCES:

http://www.gnuplotting.org/plotting-single-points/

http://www.gnuplotting.org/plotting-data/

0
votes

Here is a possible solution (which is a simple extrapolation from gnuplot conditional plotting with if), that works as long as you don't have tens of different symbols to handle.

Suppose I want to plot 2D points in a coordinate system. I have only two symbols, that I arbitrarily represented with a 0 and a 1 in the last column of my data file :

0 -0.29450470209121704 1.2279523611068726 1 
1 -0.4006965458393097 1.0025811195373535 0 
2 -0.7109975814819336 0.9022682905197144 1 
3 -0.8540692329406738 1.0190201997756958 1 
4 -0.5559651851654053 0.7677079439163208 0 
5 -1.1831613779067993 1.5692367553710938 0 
6 -0.24254602193832397 0.8055955171585083 0 
7 -0.3412654995918274 0.6301406025886536 0 
8 -0.25005266070365906 0.7788659334182739 1 
9 -0.16853423416614532 0.09659398347139359 1 
10 0.169997438788414 0.3473801910877228 0 
11 -0.5252010226249695 -0.1398928463459015 0 
12 -0.17566296458244324 0.09505800902843475 1 

To achieve what I want, I just plot my file using conditionals. Using an undefined value like 1/0 results in no plotting of the given point:

# Set styles
REG_PTS = 'pointtype 7 pointsize 1.5 linecolor rgb "purple"'
NET_PTS = 'pointtype 4 pointsize 1.5 linecolor rgb "blue"'
set grid

# Plot each category with its own style
plot "data_file" u 2:($4 == 0 ? $3 : 1/0) title "regular" @REG_PTS, \
     "data_file" u 2:($4 == 1 ? $3 : 1/0) title "network" @NET_PTS

Here is the result :

result

Hope this helps