Skip to content

Commit 0e0b7e1

Browse files
committed
fixed style errors
1 parent 0269e67 commit 0e0b7e1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

examples/misc/packed_bubbles.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
Create a packed bubble / non overlapping bubble chart to represent scalar data.
3-
In this example we plot the market share of different desktop browsers.
3+
The presented algorithm tries to move all bubbles as close to the center of
4+
mass as possible while avoiding some collisions by moving aroud colliding
5+
objects. In this example we plot the market share of different desktop
6+
browsers.
47
"""
58

69
import numpy as np
@@ -15,13 +18,15 @@
1518

1619
class BubbleChart:
1720
def __init__(self, r=None, a=None, bubble_distance=0):
18-
"""setup for bubble collapse
21+
"""
22+
setup for bubble collapse
1923
2024
Args:
2125
r (list, optional): radius of the bubbles. Defaults to None.
2226
a (list, optional): area of the bubbles. Defaults to None.
2327
Note: If r or a is sorted, the results might look weird
24-
bubble_distance (int, optional): minimal distance the bubbles should have after collapsing. Defaults to 0.
28+
bubble_distance (int, optional): minimal distance the bubbles
29+
should have after collapsing. Defaults to 0.
2530
"""
2631
if r is None:
2732
r = np.sqrt(a / np.pi)
@@ -49,15 +54,18 @@ def __len__(self):
4954
return self.n
5055

5156
def center_of_mass(self):
52-
return np.average(self.bubbles[:, :2], axis=0, weights=self.bubbles[:, 3])
57+
return np.average(
58+
self.bubbles[:, :2], axis=0, weights=self.bubbles[:, 3]
59+
)
5360

5461
def center_distance(self, bubble, bubbles):
55-
return np.sqrt(np.power(bubble[0] - bubbles[:, 0], 2)
56-
+ np.power(bubble[1] - bubbles[:, 1], 2))
62+
return np.sqrt(np.power(bubble[0] - bubbles[:, 0], 2) +
63+
np.power(bubble[1] - bubbles[:, 1], 2))
5764

5865
def outline_distance(self, bubble, bubbles):
5966
center_distance = self.center_distance(bubble, bubbles)
60-
return center_distance - bubble[2] - bubbles[:, 2] - self.bubble_distance
67+
return center_distance - bubble[2] - \
68+
bubbles[:, 2] - self.bubble_distance
6169

6270
def check_collisions(self, bubble, bubbles):
6371
distance = self.outline_distance(bubble, bubbles)
@@ -112,10 +120,10 @@ def collapse(self):
112120

113121
if moves / len(self) < 0.1:
114122
self.step_dist = self.step_dist / 2
115-
print(self.step_dist)
116123

117124
def plot(self, ax, labels, colors):
118-
"""draw the bubble plot
125+
"""
126+
draw the bubble plot
119127
120128
Args:
121129
ax (matplotlib.axes._subplots.AxesSubplot)
@@ -134,7 +142,8 @@ def plot(self, ax, labels, colors):
134142
bubble_plot = BubbleChart(a=np.array(
135143
browser_market_share['market_share']), bubble_distance=1)
136144

137-
# collapse plot 50 times. In some cases it might be useful to do this more or less often
145+
# collapse plot 50 times. In some cases it might be useful
146+
# to do this more or less often
138147
for i in range(50):
139148
bubble_plot.collapse()
140149

0 commit comments

Comments
 (0)