5

I want to plot points, each with X, Y and a color. How do I do that in Gnuplot?

cube
  • 3,867
  • 7
  • 32
  • 52

2 Answers2

9

You can try something like this:

Line plot in GnuPlot where line color is a third column in my data file?

For example:

plot "./file.dat" u 1:2:3 with points palette

where file.dat contains your data, the first column is the x axis and the second column is the y axis, the third column is the colour.

Community
  • 1
  • 1
Tom
  • 5,219
  • 2
  • 29
  • 45
3

You could consider looking at the Pyxplot plotting package http://pyxplot.org.uk, which has very similar syntax to gnuplot (albeit cleaned up considerably), and which allows point styles to be specified on a point-by-point basis. For example, in Pyxplot:

plot "file.dat" using 1:2:3 with points color rgb($4,$5,$6)

would take the RGB components for the color of each point from the 4th, 5th and 6th columns of the data file. Alternatively,

plot "file.dat" using 1:2:3 with points color $4

would read the numbers in the 4th column of the data file (call it n), and plot each point with the n-th color from the palette. If n is non-integer, say 2.5, it gives you a color half way between color 2 and color 3 in RGB space.

Dominic Ford
  • 224
  • 3
  • 2