lockdrop-simulation/lockdrop/visualization.py
Prathamesh Musale 652c69cbee Move lockdrop calculations to a module and add a experimentation notebook (#2)
- Refactor lockdrop calculations and other helper code from the simulation notebook to a python module
- Add a notebook for experimenting with lockdrop calculations
  - Add widget buttons to run calculations and export results
  - Add a script a to setup and run the notebook

Reviewed-on: #2
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2025-08-13 11:56:52 +00:00

122 lines
4.8 KiB
Python

"""
Visualization functions for lockdrop analysis.
This module contains functions for creating charts and plots to visualize
lockdrop participation and allocation data.
"""
import matplotlib.pyplot as plt
import seaborn as sns
def configure_matplotlib():
"""Configure matplotlib settings for consistent plots."""
plt.style.use('seaborn-v0_8')
sns.set_palette("husl")
plt.rcParams['figure.figsize'] = (12, 8)
plt.rcParams['font.size'] = 11
plt.rcParams['axes.titlesize'] = 14
plt.rcParams['axes.labelsize'] = 12
plt.rcParams['xtick.labelsize'] = 10
plt.rcParams['ytick.labelsize'] = 10
plt.rcParams['legend.fontsize'] = 10
plt.rcParams['axes.unicode_minus'] = False
try:
plt.rcParams['font.family'] = 'DejaVu Sans'
except:
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['DejaVu Sans', 'Liberation Sans', 'Arial', 'Helvetica']
def create_visualization(allocation_data, final_data):
"""Create comprehensive visualization plots."""
stars_counts = allocation_data['stars_counts']
galaxies_counts = allocation_data['galaxies_counts']
final_star_allocations = final_data['final_star_allocations']
final_galaxy_allocations = final_data['final_galaxy_allocations']
fig = plt.figure(figsize=(20, 10))
gs = fig.add_gridspec(2, 3, hspace=0.35, wspace=0.35)
fig.suptitle('Lockdrop Analysis', fontsize=18, fontweight='bold', y=0.98)
# 1. Star Participation Distribution
ax1 = fig.add_subplot(gs[0, 0])
star_years = [1, 2, 3, 4, 5]
star_counts = [stars_counts[year] for year in star_years]
bars1 = ax1.bar(range(len(star_years)), star_counts,
color=['#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728'], alpha=0.8)
ax1.set_xlabel('Lock Period (Years)')
ax1.set_ylabel('Number of Stars')
ax1.set_title('Star Participation by Lock Period', fontweight='bold')
ax1.set_xticks(range(len(star_years)))
ax1.set_xticklabels(star_years)
for i, count in enumerate(star_counts):
height = bars1[i].get_height()
ax1.text(bars1[i].get_x() + bars1[i].get_width()/2., height + height*0.01,
f'{count:,}', ha='center', va='bottom', fontweight='bold', fontsize=9)
# 2. Galaxy Participation Distribution
ax2 = fig.add_subplot(gs[0, 1])
galaxy_counts = [galaxies_counts[year] for year in star_years]
bars2 = ax2.bar(range(len(star_years)), galaxy_counts,
color=['#9467bd', '#c5b0d5', '#8c564b', '#c49c94', '#e377c2'], alpha=0.8)
ax2.set_xlabel('Lock Period (Years)')
ax2.set_ylabel('Number of Galaxies')
ax2.set_title('Galaxy Participation by Lock Period', fontweight='bold')
ax2.set_xticks(range(len(star_years)))
ax2.set_xticklabels(star_years)
for i, count in enumerate(galaxy_counts):
height = bars2[i].get_height()
ax2.text(bars2[i].get_x() + bars2[i].get_width()/2., height + height*0.01,
f'{count:,}', ha='center', va='bottom', fontweight='bold', fontsize=9)
# 3. Star Allocations
ax3 = fig.add_subplot(gs[0, 2])
star_alloc_values = [float(final_star_allocations[year]) for year in star_years]
bars3 = ax3.bar(range(len(star_years)), star_alloc_values,
color=['#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728'], alpha=0.8)
ax3.set_xlabel('Lock Period (Years)')
ax3.set_ylabel('Allocation per Star ($Z)')
ax3.set_title('Star Allocations by Lock Period', fontweight='bold')
ax3.set_xticks(range(len(star_years)))
ax3.set_xticklabels(star_years)
for i, allocation in enumerate(star_alloc_values):
height = bars3[i].get_height()
ax3.text(bars3[i].get_x() + bars3[i].get_width()/2., height + height*0.01,
f'{allocation:,.0f}', ha='center', va='bottom', fontweight='bold', fontsize=9)
# 4. Galaxy Allocations
ax4 = fig.add_subplot(gs[1, 0])
galaxy_alloc_values = [float(final_galaxy_allocations[year]) for year in star_years]
bars4 = ax4.bar(range(len(star_years)), galaxy_alloc_values,
color=['#9467bd', '#c5b0d5', '#8c564b', '#c49c94', '#e377c2'], alpha=0.8)
ax4.set_xlabel('Lock Period (Years)')
ax4.set_ylabel('Allocation per Galaxy ($Z)')
ax4.set_title('Galaxy Allocations by Lock Period', fontweight='bold')
ax4.set_xticks(range(len(star_years)))
ax4.set_xticklabels(star_years)
for i, allocation in enumerate(galaxy_alloc_values):
height = bars4[i].get_height()
ax4.text(bars4[i].get_x() + bars4[i].get_width()/2., height + height*0.01,
f'{allocation:,.0f}', ha='center', va='bottom', fontweight='bold', fontsize=9)
# Hide remaining subplots
ax5 = fig.add_subplot(gs[1, 1])
ax5.axis('off')
ax6 = fig.add_subplot(gs[1, 2])
ax6.axis('off')
plt.subplots_adjust(bottom=0.08, top=0.88, left=0.05, right=0.98)
plt.show()