Coloring Close Points

I have a dense set of points on the plane. I want them to be painted so that the points that are close to each other have the same color and a different color if they are far away. For simplicity, suppose there are, say, 5 different colors to choose from. It turns out that I have no idea how to do this.

I am using Tkinter with Python by the way

+4
source share
4 answers

If you can use any color you want, you can use the fact that the colors are (almost) continuous. color the dots according to their x, y coordinates, so that you get as a side effect that the close dots will have 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 (x-min_x / (max_x-min_x)), so it will give 0 for a point with a minimum value of x and 1 for a point with a maximum value of x.

If you really need to use only a small number of colors and close the point have the same color , then you will need to do clustering according to your data ( K-means is a simple and widely used algorithm). After clustering, you simply assign a color to each point according to its cluster identifier. Python has some good implementations, including scipy clustering .

+2
source

I would start by determining the concentration of spots in the plane. Find the centers of these agglomerations and assign them each unique color. Then for other points, you can simply calculate the color using the linear principle. For example, if one center is red and the other yellow, the point somewhere in the middle will turn orange.

I would probably use some exponential function instead of the linear principle. This will save point groups of more or less one color, only giving a noticeable color change to distant points or, more precisely, far and somewhere between points.

0
source

One approach is to go through your points and break them into groups with a β€œcenter”. Since you have 5 colors, you will have 5 sets. You compare the distance of a new point from each of the centers and then place it in the same group as the nearest one.

Each set corresponds to a different color, so you can simply build it after completing this split.

0
source

The problem area is well-developed cluster analysis and the Cluster suite with PyCluster is a good start.

0
source

Source: https://habr.com/ru/post/1311946/


All Articles