If you can use whatever color you want, you can use that fact that colors are (almost) continuous. color the points according to their x,y coordinates, so you'll get as a side effect that close points will have a somewhat similar color.
You can use something like
point.color(R,G,B) = ( point.normalized_x, 0.5, 1-point.normalized.y )
where normalized_x is (x-min_x / (max_x-min_x)), so it would give 0 for the point with minimal x value, and 1 for point with maximal x value.
If you really need to use only a small number of colors and have close point have the exact same color, then you'll have to do some clustering on your data (K-means being a simple and widely used algorithm). After clustering, you just assign each point a color according to its cluster's id. Python has some good implementations, including scipy's clustering.