ANOVA Violin Plot

Cryptocurrency Volatility ANOVA

Comparing daily price volatility distributions across major cryptocurrencies.

Output
Cryptocurrency Volatility ANOVA
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

np.random.seed(1010)

# Daily percentage change (volatility)
bitcoin = np.random.laplace(0, 2.5, 365)
ethereum = np.random.laplace(0, 3.2, 365)
solana = np.random.laplace(0, 5.5, 365)
dogecoin = np.random.laplace(0, 7.0, 365)

F_stat, p_value = stats.f_oneway(np.abs(bitcoin), np.abs(ethereum), np.abs(solana), np.abs(dogecoin))

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

# Crypto brand colors
colors = ['#F5B027', '#276CF5', '#9C2007', '#F5D327']

parts = ax.violinplot([bitcoin, ethereum, solana, dogecoin], 
                       positions=[1, 2, 3, 4], showmeans=True, showmedians=True, widths=0.75)

for i, pc in enumerate(parts['bodies']):
    pc.set_facecolor(colors[i])
    pc.set_alpha(0.7)
    pc.set_edgecolor(colors[i])
    pc.set_linewidth(2)

parts['cmeans'].set_color('#6CF527')
parts['cmeans'].set_linewidth(2.5)
parts['cmedians'].set_color('white')
for partname in ['cbars', 'cmins', 'cmaxes']:
    parts[partname].set_color('#444444')

# Zero line
ax.axhline(y=0, color='white', linestyle='-', alpha=0.3, linewidth=1)

# Volatility and market cap annotations at bottom
labels = ['Bitcoin\n(BTC)', 'Ethereum\n(ETH)', 'Solana\n(SOL)', 'Dogecoin\n(DOGE)']
stds = [np.std(bitcoin), np.std(ethereum), np.std(solana), np.std(dogecoin)]
market_caps = ['$1.3T', '$380B', '$85B', '$23B']
for i, (std, cap, color) in enumerate(zip(stds, market_caps, colors)):
    ax.text(i+1, -38, f'σ={std:.1f}% | {cap}', ha='center', fontsize=8, color=color, fontweight='bold')

# Stats box - top center
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.2e} | 365-day analysis"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#0d1117', edgecolor='#F5B027', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=9, color='white',
        ha='center', va='bottom', fontfamily='monospace', bbox=bbox)

ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(labels, fontsize=10, color='white')
ax.set_ylabel('Daily Price Change (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('Cryptocurrency Daily Volatility Comparison', 
             fontsize=14, color='white', fontweight='bold', pad=25)

ax.tick_params(colors='#888888')
for spine in ax.spines.values():
    spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)
ax.set_ylim(-45, 40)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support