Violin Plot

Exoplanet Orbital Periods

Distribution of discovered exoplanet orbits by detection method

Output
Exoplanet Orbital Periods
Python
import matplotlib.pyplot as plt
import numpy as np

# Exoplanet orbital periods by detection method
np.random.seed(42)
methods = ['Transit', 'Radial\nVelocity', 'Direct\nImaging', 'Microlensing', 'Timing']
# Orbital period in days (log scale simulation)
periods = [
    np.random.lognormal(2, 1.2, 150),        # Transit - bias short
    np.random.lognormal(4, 1.5, 150),        # RV - medium
    np.random.lognormal(8, 0.8, 150),        # Direct - long periods
    np.random.lognormal(6, 2, 150),          # Microlensing - varied
    np.random.lognormal(1.5, 0.5, 150),      # Timing - short
]

# Space-themed colors
colors = ['#06B6D4', '#8B5CF6', '#F59E0B', '#10B981', '#EC4899']

# Create figure with dark space theme
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#0C0A20')
ax.set_facecolor('#0C0A20')

# Add stars background
for _ in range(80):
    ax.scatter(np.random.uniform(-0.5, 4.5), np.random.uniform(0, 6),
               s=np.random.uniform(0.5, 2), c='white', alpha=np.random.uniform(0.3, 0.8))

vp = ax.violinplot([np.log10(p) for p in periods], positions=range(len(methods)), 
                   widths=0.7, showmeans=False, showmedians=False, showextrema=False)

for i, body in enumerate(vp['bodies']):
    body.set_facecolor(colors[i])
    body.set_edgecolor(colors[i])
    body.set_linewidth(1)
    body.set_alpha(0.3)
    
    # Glow layers
    path = body.get_paths()[0]
    for lw, alpha in [(10, 0.08), (6, 0.15), (3, 0.3)]:
        ax.plot(path.vertices[:, 0], path.vertices[:, 1],
                color=colors[i], linewidth=lw, alpha=alpha)
    ax.plot(path.vertices[:, 0], path.vertices[:, 1],
            color=colors[i], linewidth=1.5, alpha=0.9)

# Earth reference line
earth_period = np.log10(365.25)
ax.axhline(earth_period, color='#22D3EE', linewidth=2, linestyle='--', alpha=0.6)
ax.text(4.6, earth_period, 'Earth', fontsize=10, color='#22D3EE', 
        fontweight='500', va='center')

# Discovery count annotations
counts = [3800, 1050, 65, 180, 45]
for i, (period, count) in enumerate(zip(periods, counts)):
    median = np.log10(np.median(period))
    ax.scatter(i, median, c='white', s=80, zorder=10,
               edgecolor=colors[i], linewidth=2)
    ax.text(i, 5.7, f'n={count}', ha='center', fontsize=9,
            color=colors[i], fontweight='600')

# Styling
ax.set_xticks(range(len(methods)))
ax.set_xticklabels(methods, fontsize=10, fontweight='600', color='white')
ax.set_ylabel('Orbital Period (log₁₀ days)', fontsize=12, fontweight='500', color='#A5B4FC')
ax.set_ylim(-0.5, 6.5)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#312E81')
ax.spines['bottom'].set_color('#312E81')
ax.tick_params(colors='#A5B4FC', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.15, color='#6366F1')

# Secondary y-axis labels
ax2_ticks = [0, 1, 2, 3, 4, 5, 6]
ax2_labels = ['1d', '10d', '100d', '3yr', '27yr', '274yr', '2740yr']
ax.set_yticks(ax2_ticks)
ax.set_yticklabels(ax2_labels, fontsize=9, color='#A5B4FC')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support