Hierarchical
Static
Circle Packing
Circle packing is a hierarchical visualization where data is represented as circles containing other circles. The area of each circle is proportional to the value it represents, making it effective for showing part-to-whole relationships in nested data. Unlike treemaps which use rectangles, circle packing can sometimes waste space but creates a more organic, visually appealing representation. It's particularly effective for organizational charts, file systems, and budget allocations.
Example Visualization
.png&w=1920&q=75)
Try this prompt
"Use circlify with matplotlib to create a circle packing diagram visualizing the 'Budget Allocation' by 'Department' and 'Sub-category'. Generate a proper example dataset to demonstrate this visualization."
Generate this nowPython Code Example
example.py
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import circlify
# Example hierarchical data
df = pd.DataFrame({
'Department': ['Marketing', 'Marketing', 'Engineering', 'Engineering',
'Sales', 'Sales', 'HR', 'HR'],
'Subcategory': ['Advertising', 'Social Media', 'Development', 'Testing',
'Direct Sales', 'Online Sales', 'Recruitment', 'Training'],
'Budget': [30000000, 20000000, 50000000, 15000000,
25000000, 18000000, 12000000, 8000000]
})
# Build hierarchy for circlify
data = []
for dept, group in df.groupby('Department'):
children = [{'id': row['Subcategory'], 'datum': row['Budget']}
for _, row in group.iterrows()]
data.append({'id': dept, 'datum': group['Budget'].sum(), 'children': children})
# Compute circle positions
circles = circlify.circlify(data, show_enclosure=False)
# Plot
fig, ax = plt.subplots(figsize=(14, 14))
ax.set_xlim(-1.2, 1.2)
ax.set_ylim(-1.2, 1.2)
ax.set_aspect('equal')
ax.axis('off')
for circle in circles:
x, y, r = circle.x, circle.y, circle.r
if circle.level == 1: # Department
ax.add_patch(patches.Circle((x, y), r, facecolor='#f0f0f0',
edgecolor='#999', linewidth=2))
ax.text(x, y + r, circle.ex['id'].upper(), ha='center',
fontsize=14, fontweight='bold')
elif circle.level == 2: # Subcategory
ax.add_patch(patches.Circle((x, y), r * 0.95, facecolor='steelblue',
edgecolor='white'))
plt.title('Budget Allocation by Department', fontsize=16)
plt.show()Common Use Cases
- 1Corporate budget allocation visualization
- 2File system size analysis
- 3Organizational structure display
- 4Market segmentation by size
Pro Tips
Use contrasting colors for different hierarchy levels
Add labels only for circles large enough to display them
Consider treemaps for more space-efficient layouts