Reputation: 2782
I have a file with different series like:
x0_1 y0_1 A_0
x0_2 y0_2 B_0
...
x0_n y0_n N_0
x1_1 y1_1 A_1
x1_2 y1_2 B_1
...
x1_n y1_n N_1
If I do plot "data.txt" u 1:2:3 w lp lc palette
I can plot all the series with different lines each. But how can I put a different symbol for each line?
Upvotes: 0
Views: 559
Reputation: 1569
The answer has already been accepted, but please allow me to put another (somewhat simpler) answer here.
You can successfully access each series of your data by specifying index N
in the plot command (I forgot this point in the previous answer). This allows you to treat your data as if there are multiple datasets in a single file.
The script looks like this,
set key noautotitle
array pointtype[3] = [5, 7, 9]
array linecolor[3] = [1, 4, 6]
plot for [i=0:2] "test.dat" index i using 1:2 \
with linespoints ps 3 pt pointtype[i+1] lc linecolor[i+1] \
title sprintf("series %i", i)
Using your version of gnuplot, you'd still be able to show the plot including the legend in this way.
Upvotes: 1
Reputation: 25724
Just for completeness, here is a version which even works down to gnuplot 4.6 and with minor adaptions even with gnuplot 4.4. You can use index
to address blocks (see help index
).
Code: (using @binzo's test.dat
)
### plot different sets (works with gnuplot 4.6)
reset
myColor(i) = word("1 2 3",i+1)
myPts(i) = word("5 7 9", i+1)
set key top left
stats 'test.dat' u 1 nooutput # get the number of blocks
plot for [i=0:int(STATS_blocks)-1] 'test.dat' u 1:2 index i \
w lp ps 3 pt myPts(i) lc myColor(i) title sprintf("series %i", i)
### end of code
Result: (gnuplot 4.6)
Upvotes: 1
Reputation: 1569
Your data is divided into different series by two blank lines. If you give an index number 0, 1, 2 for each series, you can access the index number by column(-2)
in using
specification. The column(-2)
is called 'pseudocolumns' in gnuplot. Please, see help psuedocolumns
for details.
Here's an example script with this in mind.
set key noautotitle
set xrange [0:5]
set yrange [0:7]
plot "test.dat" using 1:2:(column(-2)+1):(column(-2)+1)
with linespoints ps 3 pt variable lc variable
In this example, the point types and line colors are assigned in order. However, if your gnuplot is an array-enabled version, you can also set the point type and line color as you wish, like this.
array pointtype[3] = [5, 7, 9]
array linecolor[3] = [1, 4, 6]
plot "test.dat" using 1:2:(pointtype[column(-2)+1]):(linecolor[column(-2)+1])
with linespoints ps 3 pt variable lc variable
I used sample data like this,
1 1 5
2 1 6
3 2 4
4 3 5
1 2 7
2 3 5
3 3 4
4 4 2
1 3 6
2 4 4
3 4 3
4 6 2
In this plot, the legend (or key) for individual lines cannot be displayed in a simple way. If you're using version 5.2.6 or later, you can use the keyentry style.
set key noautotitle
array pointtype[3] = [5, 7, 9]
array linecolor[3] = [1, 4, 6]
plot "test.dat" using 1:2:(pointtype[column(-2)+1]):(linecolor[column(-2)+1]) \
with linespoints ps 3 pt variable lc variable, \
for [i=0:2] keyentry with linespoints ps 3 pt pointtype[i+1] lc linecolor[i+1] \
title sprintf("series %i", i)
Upvotes: 1