Sunburst Chart

Python Package Structure

Dark-themed sunburst chart showing Python package internal structure from package root to submodules to specific files.

Output
Python Package Structure
Python
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(figsize=(12, 10), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Inner ring - Top-level modules
mod_sizes = [30, 25, 20, 15, 10]
mod_labels = ['core/', 'api/', 'utils/', 'models/', 'tests/']
mod_colors = ['#5314E6', '#27D3F5', '#6CF527', '#F5B027', '#F5276C']

# Outer ring - Files
file_sizes = [10, 10, 10, 10, 8, 7, 8, 7, 5, 8, 7, 5, 5]
file_colors = ['#5314E6', '#7B4DFF', '#9C7AFF',
               '#27D3F5', '#5CE8FF', '#8CF2FF',
               '#6CF527', '#8FFF5C', '#B2FF8C',
               '#F5B027', '#FFCC5C',
               '#F5276C', '#FF5A94']

wedges_outer, _ = ax.pie(file_sizes, radius=1, colors=file_colors,
       wedgeprops=dict(width=0.3, edgecolor='#0a0a0f', linewidth=2))

wedges_inner, _ = ax.pie(mod_sizes, radius=0.7, colors=mod_colors,
       wedgeprops=dict(width=0.3, edgecolor='#0a0a0f', linewidth=2))

# Add module labels
for i, (wedge, label) in enumerate(zip(wedges_inner, mod_labels)):
    ang = (wedge.theta2 - wedge.theta1) / 2 + wedge.theta1
    x = 0.55 * np.cos(np.radians(ang))
    y = 0.55 * np.sin(np.radians(ang))
    ax.text(x, y, label, ha='center', va='center', fontsize=10, 
            color='white', fontweight='bold')

centre_circle = plt.Circle((0, 0), 0.4, fc='#0a0a0f', ec='#334155', linewidth=2)
ax.add_artist(centre_circle)
ax.text(0, 0, 'mypackage/\n25 modules', ha='center', va='center',
        fontsize=11, color='white', fontweight='bold')

# Legend
file_labels = ['engine.py', 'config.py', 'base.py', 'routes.py', 'handlers.py', 
               'middleware.py', 'helpers.py', 'validators.py', 'logger.py',
               'user.py', 'product.py', 'test_core.py', 'test_api.py']
ax.legend(wedges_outer, file_labels, loc='center left', bbox_to_anchor=(1.05, 0.5),
          fontsize=9, frameon=True, facecolor='#1e293b', edgecolor='#334155',
          labelcolor='white', title='Files', title_fontsize=10)

ax.set_title('Python Package Structure', fontsize=18, color='#f8fafc',
             fontweight='bold', pad=20)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Part-to-Whole

Did this help you?

Support PyLucid to keep it free & growing

Support