KDE Plot
Cryptocurrency Volatility KDE
Density distribution of hourly price volatility across major cryptocurrencies
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(444)
BG_COLOR = '#0d1117'
TEXT_COLOR = 'white'
# Hourly volatility (%)
bitcoin = np.abs(np.random.normal(0, 1.5, 600))
ethereum = np.abs(np.random.normal(0, 2.0, 600))
altcoins = np.abs(np.random.normal(0, 3.5, 600))
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x_range = np.linspace(0, 15, 500)
for data, color, label in [(bitcoin, '#F5B027', 'Bitcoin'),
(ethereum, '#4927F5', 'Ethereum'),
(altcoins, '#F5276C', 'Altcoins')]:
kde = gaussian_kde(data)
density = kde(x_range)
ax.plot(x_range, density, color=color, linewidth=2.5, label=label)
ax.fill_between(x_range, density, alpha=0.3, color=color)
ax.axvline(5, color='#ef4444', linestyle='--', alpha=0.8, linewidth=2)
ax.text(5.2, ax.get_ylim()[1]*0.8, 'High Risk', color='#ef4444', fontsize=10)
ax.set_xlabel('Hourly Volatility (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Cryptocurrency Volatility Distribution', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#888888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333333')
ax.legend(facecolor=BG_COLOR, edgecolor='#333333', labelcolor=TEXT_COLOR, fontsize=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕