Search code examples
gnuplot

plot every subsequence with a different color using gnuplot


I have a list of 105 sorted values in ascending order. I divided that list in 5 subsequences as shown in the following table:

id  Seq1    Seq2    Seq3    Seq4    Seq5
1   696.99  958.79  989.02  1018.28 1078.3
2   869.21  959.26  989.02  1018.28 1078.3
3   898.73  959.44  989.02  1018.28 1078.55
4   898.73  959.44  989.02  1018.28 1078.55
5   898.73  959.44  989.21  1018.28 1078.55
6   898.73  959.44  989.21  1018.28 1078.55
7   898.73  959.44  989.21  1018.28 1078.55
8   898.79  959.44  989.21  1018.52 1078.69
9   898.79  959.51  989.21  1018.52 1078.69
10  898.79  959.51  989.21  1018.52 1078.69
11  899.27  988.52  989.26  1018.52 1078.69
12  899.27  988.65  989.26  1018.52 1078.69
13  899.27  988.65  989.26  1018.52 1078.69
14  899.44  988.65  989.26  1019.0  1078.73
15  928.65  988.65  989.51  1019.0  1078.73
16  928.73  989.0   989.51  1019.26 1078.73
17  929.26  989.0   989.51  1078.3  1078.73
18  958.73  989.0   989.51  1078.3  1078.73
19  958.79  989.02  989.51  1078.3  1078.73
29  958.79  989.02  1013.0  1078.3  1144.2
21  958.79  989.02  1013.0  1078.3  1144.21

My question is how can I plot all the 5 sub-sequences in a continuous manner and each with different color. I used the following script. But the problem is that it is plotting them separately as shown in the following figure.

enter image description here

#!/bin/bash

#set key outside
unset key

set title "5 sequences des prix triés pour 120 jours avant la date de départ"

set xlabel "séquences"
set ylabel "Prix"


# set xlabel "Jour de recherche avant la date de départ"
# set ylabel "Nombre de dates de baisses pour chaque jour de recherche"

set xtics font ", 11"

set datafile separator ","
# set autoscale
set terminal pngcairo dashed
set output 'sequence.png'
set key autotitle columnhead


plot  "test.csv" every 4 u 2:xticlabels(1) w l lw 2 lc 1 ,\
        "test.csv" every 4 u 3:xticlabels(1) w l lw 2 lc 2 ,\
        "test.csv" every 4 u 4:xticlabels(1) w l lw 2 lc 3,\
        "test.csv" every 4 u 5:xticlabels(1) w l lw 2 lc 4,\
        "test.csv" every 4 u 5:xticlabels(1) w l lw 2 lc 5

Solution

  • plot for [IDX=0:4] 'prix.txt' u ($1 + IDX*21):(column(IDX+2)) title columnhead(IDX+2) w lp
    

    enter image description here