-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_bubble.py
27 lines (24 loc) · 907 Bytes
/
plot_bubble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np
import seaborn as sns
sns.set()
sns.set_style("white")
sns.set_context("poster")
from bubbleplot import positions
# Obtain the positions of the new centres
radii = tuple(range(1,30))
centres = positions.spawn_bubbles(radii)
new_centres = positions.foptimise_positions(radii, centres, n_steps=10000, learning_rate=0.00001, rep_const=2000)
# Plot the bubble chart
fig, ax = plt.subplots(figsize=(7,7))
ax.set_axis_off()
radii = np.asarray(radii)
circ_list = []
for i in range(len(radii)):
circ = Ellipse((new_centres[i,0], new_centres[i,1]), width=radii[i]*2, height=radii[i]*2, alpha=0.5)
circ_list.append(circ)
ax.add_patch(circ)
ax.set_xlim((min(new_centres[:,0])-max(radii),max(new_centres[:,0])+max(radii)))
ax.set_ylim((min(new_centres[:,1])-max(radii),max(new_centres[:,1])+max(radii)))
plt.show()