title: Clustering points in 3D plane
body: <p>Suppose we have 1000 random data points in a cube (as shown in the following image). The distribution of points in X and Y directions are uniform but not in Z direction. As we get deeper, the data points are denser. Is there any straightforward way in python to cluster these data points such that:</p>
  
  <ul>
  <li>each cluster has equal size</li>
  <li>each cluster consists of local points, i.e., each cluster consists of points being close to each other.</li>
  </ul>
  
  <p>I have already tried K-means clustering from Scipy package but it did not give me a good result and the points of each cluster were very widespread rather than being concentrated.</p>
  
  <p><a href="https://i.stack.imgur.com/TZGhh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TZGhh.jpg" alt="enter image description here"></a></p>