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
(self, area, bubble_spacing=0)
| 23 | |
| 24 | class BubbleChart: |
| 25 | def __init__(self, area, bubble_spacing=0): |
| 26 | """ |
| 27 | Setup for bubble collapse. |
| 28 | |
| 29 | Parameters |
| 30 | ---------- |
| 31 | area : array-like |
| 32 | Area of the bubbles. |
| 33 | bubble_spacing : float, default: 0 |
| 34 | Minimal spacing between bubbles after collapsing. |
| 35 | |
| 36 | Notes |
| 37 | ----- |
| 38 | If "area" is sorted, the results might look weird. |
| 39 | """ |
| 40 | area = np.asarray(area) |
| 41 | r = np.sqrt(area / np.pi) |
| 42 | |
| 43 | self.bubble_spacing = bubble_spacing |
| 44 | self.bubbles = np.ones((len(area), 4)) |
| 45 | self.bubbles[:, 2] = r |
| 46 | self.bubbles[:, 3] = area |
| 47 | self.maxstep = 2 * self.bubbles[:, 2].max() + self.bubble_spacing |
| 48 | self.step_dist = self.maxstep / 2 |
| 49 | |
| 50 | # calculate initial grid layout for bubbles |
| 51 | length = np.ceil(np.sqrt(len(self.bubbles))) |
| 52 | grid = np.arange(length) * self.maxstep |
| 53 | gx, gy = np.meshgrid(grid, grid) |
| 54 | self.bubbles[:, 0] = gx.flatten()[:len(self.bubbles)] |
| 55 | self.bubbles[:, 1] = gy.flatten()[:len(self.bubbles)] |
| 56 | |
| 57 | self.com = self.center_of_mass() |
| 58 | |
| 59 | def center_of_mass(self): |
| 60 | return np.average( |
nothing calls this directly
no test coverage detected