docstr: Setup for bubble collapse.
  
  Parameters
  ----------
  area : array-like
      Area of the bubbles.
  bubble_spacing : float, default: 0
      Minimal spacing between bubbles after collapsing.
  
  Notes
  -----
  If "area" is sorted, the results might look weird.
docstr_tok: ["Setup","for","bubble","collapse",".","Parameters","--","--","--","--","--","area",":","array-like","Area","of","the","bubbles",".","bubble_spacing",":","float",",","default",":","0","Minimal","spacing","between","bubbles","after","collapsing",".","Notes","--","--","-","If","``","area","''","is","sorted",",","the","results","might","look","weird","."]
code: def __init__(self, area, bubble_spacing=0):
      """
      Setup for bubble collapse.
  
      Parameters
      ----------
      area : array-like
          Area of the bubbles.
      bubble_spacing : float, default: 0
          Minimal spacing between bubbles after collapsing.
  
      Notes
      -----
      If "area" is sorted, the results might look weird.
      """
      area = np.asarray(area)
      r = np.sqrt(area / np.pi)
  
      self.bubble_spacing = bubble_spacing
      self.bubbles = np.ones((len(area), 4))
      self.bubbles[:, 2] = r
      self.bubbles[:, 3] = area
      self.maxstep = 2 * self.bubbles[:, 2].max() + self.bubble_spacing
      self.step_dist = self.maxstep / 2
  
      # calculate initial grid layout for bubbles
      length = np.ceil(np.sqrt(len(self.bubbles)))
      grid = np.arange(length) * self.maxstep
      gx, gy = np.meshgrid(grid, grid)
      self.bubbles[:, 0] = gx.flatten()[: len(self.bubbles)]
      self.bubbles[:, 1] = gy.flatten()[: len(self.bubbles)]
  
      self.com = self.center_of_mass()
  
file_path: matplotlib/galleries/examples/misc/packed_bubbles.py
imports: import matplotlib.pyplot
  import numpy
label_desc: Use image node_id 1 to create a new BubbleChart object  with example: obj = BubbleChart(area, bubble_spacing)