2

Im trying to perform a KD-tree on a set of x,y coordinate pairs for spatial indexing them. I found scipy.spatial.kdtree to perform this quickly. However I can't seem to manage plotting hyperrectangles of the kdtree (Im using matplotlib).

Does anyone know how to fetch the hyperrectangles generated by the algorithm?

2
  • Couldnt attach image, here is my desired output: A kd-tree. Commented Jan 31, 2022 at 9:45
  • Please provide enough code so others can better understand or reproduce the problem. Commented Feb 9, 2022 at 22:36

1 Answer 1

0

how to fetch the hyperrectangles generated by the algorithm ?

the trick is to generate them as you go along: extend wikipedia K-d tree with e.g.

class Node( namedtuple( "Node",  # aka Box
"level "    # 0 ..
"axis "     # 0 .. Dim
"mid "      # the point with middle x / middle y
"lo hi "    # corners, inbox(p): lo <= p <= hi
"L R "      # left, right Nodes or None
"points "   # if needed / leaves only
)):
...

Code to build (no query yet) might be under my gists.
A sample plot: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.