A pure Python implementation of a circle packing algorithm
Project description
packcircles
A pure Python implementation of the circle packing algorithm detailed in Wang et al. (2006). Visualization of large hierarchical data by circle packing. Proc of the SIGCHI, 517-520.
Installation
Using pip:
pip install packcircles
or directly using setup.py:
git clone https://github.com/mhtchan/packcircles.git
cd packcircles
python setup.py install
Usage
The function pack takes an iterable of the radii of the circles to pack and returns a generator that yields the layout of each circle as tuples in the form (x_coordinate, y_coordinate, radius).
Example
import packcircles as pc
circles = pc.pack([15,5,7,12])
print(list(circles))
## [(-15.579319782711305, 4.287939798231928, 15), (4.4206802172886945, 4.287939798231928, 5), (2.9206802172886945, -7.6179411015587295, 7), (20.647637933172685, -0.7801804930509242, 12)]
The layout in the gif at the top of the page can be generated by the following code:
import packcircles as pc
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
radii = [28,12,51,26,10,16,24,25,59,11,29,40,16,11,10,26,39,16,48,36,28]
fig, ax = plt.subplots()
cmap = get_cmap('coolwarm_r')
circles = pc.pack(radii)
for (x,y,radius) in circles:
patch = plt.Circle(
(x,y),
radius,
color=cmap(radius/max(radii)),
alpha=0.65
)
ax.add_patch(patch)
fig.set_figheight(15)
fig.set_figwidth(15)
ax.set(xlim=(-150, 140), ylim=(-180, 170))
plt.axis('off')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file packcircles-0.14.tar.gz.
File metadata
- Download URL: packcircles-0.14.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13e9cc8978886b21faa19648b61b8c45fbca055c084b35347892bcb76d0b5083
|
|
| MD5 |
bef44f3915cb7602b4b7003742f2ea63
|
|
| BLAKE2b-256 |
db460dbdefe27b67b6ccf86bdf6daa2efa5ec047aab24714d6f9b7b9269e4f88
|
File details
Details for the file packcircles-0.14-py3-none-any.whl.
File metadata
- Download URL: packcircles-0.14-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b58511187c7beb9ffacc750eff6a87b0dbfbc5e8d88f8d9fb632d7f2a96ad8d1
|
|
| MD5 |
67e2b16f03636ff45831a1907822c172
|
|
| BLAKE2b-256 |
e30c1147e896cab9a53cf1c3a213f274db6ea9997d4681cb975f5cf701b00988
|