1

how can I use gnuplot to plot isolated points(not connected points): the x axis must be the first column which is the date, the y axis is the second columns the 3rd column must be the color of the point(colors are defined into ranges (ex: from 1 to 3 red, from 4 to 6 green...)

1999-01-19  21  0
2009-07-01  0   1
2008-08-20  2   1
2008-12-18  1   1
2004-05-12  4   1
2009-07-29  2   1
2008-08-07  0   1
2006-03-08  1   1
2004-08-31  9   2
2001-03-27  12  2
2009-08-19  0   2
2010-07-14  2   3
2009-06-24  4   3
2009-11-11  33  4
2010-10-13  5   4
2012-02-22  34  4
2011-05-11  2   5
zoma.saf
  • 558
  • 3
  • 6
  • 14
  • possible duplicate of [Vary point color in GNUPLOT based on value of one column](http://stackoverflow.com/questions/8717805/vary-point-color-in-gnuplot-based-on-value-of-one-column) – Schorsch Sep 27 '13 at 12:37
  • or a possible duplicate of [vary point color based on column value for multiple data blocks gnuplot](http://stackoverflow.com/questions/12427704/vary-point-color-based-on-column-value-for-multiple-data-blocks-gnuplot) – Schorsch Sep 27 '13 at 12:38

2 Answers2

1

There are several ways to do that:

You can define several line style and then use linecolor variable, which allows you to use the last column as line style index:

set timefmt '%Y-%m-%d'
set xdata time
set format x '%Y-%m'

set style increment user
set style line 1 lc rgb 'red'
set style line 2 lc rgb 'blue'
set style line 3 lc rgb 'green'
set style line 4 lc rgb 'magenta'
set style line 5 lc rgb 'yellow'

set style data points
plot 'data.txt' using 1:2:3 linecolor variable pt 7 ps 2 t ''

The result is:

enter image description here

This requires you to define as many line styles as you have colors.

Alternatively you can define a respective color palette and use linecolor palette to do the coloring of the points:

set timefmt '%Y-%m-%d'
set xdata time
set format x '%Y-%m'

set cbrange [1:6]
set palette defined (1 'red', 3.5 'red', 3.5 'green', 6 'green')

set style data points
unset colorbox
plot 'data.txt' using 1:2:3 linecolor palette pt 7 ps 2 t ''

When using this, you must pay attention, that the cbrange and the values used for the palette defined match (here 1 and 6), because in general the values of the palette are adapted to match the color range.

The above script gives the result:

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • thanks alot, it helped me a lot! but what should I write if I want to assign the color automatically according to the 3rd column value (ignore the ranges idea plz) ex: value 1=> red value 2=> blue value 3=> green and so on! – zoma.saf Sep 28 '13 at 09:04
  • @zoma.saf That's what `linecolor variable` does, which I mentioned at the beginning of the answer. I expanded this part to a full script, see the edited answer. – Christoph Sep 28 '13 at 10:58
0

Some solution could be:

plot for [i=0:5] 'cp.txt' using ( i==$3 ? $1 : 1/0 ):2 notitle with points linestyle i
ztik
  • 3,482
  • 16
  • 34