Violin Plot

Neon Violin Plot

Dark theme violin plot with neon glow effects

Output
Neon Violin Plot
Python
import matplotlib.pyplot as plt
import numpy as np

# Data
np.random.seed(42)
data = [np.random.normal(loc, 1.2, 200) for loc in [4, 6, 5, 7, 5.5]]
labels = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon']

# Neon colors
neon_colors = ['#00FFFF', '#FF00FF', '#00FF00', '#FF6B00', '#FF1493']

# Create dark figure
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0F172A')
ax.set_facecolor('#0F172A')

# Violin plot
vp = ax.violinplot(data, positions=range(len(data)), widths=0.75,
                   showmeans=False, showmedians=True, showextrema=False)

# Style with glow effect
for i, body in enumerate(vp['bodies']):
    body.set_facecolor(neon_colors[i])
    body.set_edgecolor(neon_colors[i])
    body.set_linewidth(2)
    body.set_alpha(0.3)

# Add glow outline
for i, body in enumerate(vp['bodies']):
    path = body.get_paths()[0]
    for lw, alpha in [(8, 0.1), (5, 0.2), (2, 0.4)]:
        ax.plot(path.vertices[:, 0], path.vertices[:, 1],
                color=neon_colors[i], linewidth=lw, alpha=alpha)

vp['cmedians'].set_color('white')
vp['cmedians'].set_linewidth(2)

# Add scatter overlay
for i, d in enumerate(data):
    jitter = np.random.uniform(-0.08, 0.08, 30)
    sample = np.random.choice(d, 30, replace=False)
    ax.scatter(i + jitter, sample, c=neon_colors[i], s=15, alpha=0.6,
               edgecolor='none')

# Customize axes
ax.set_xticks(range(len(data)))
ax.set_xticklabels(labels, fontsize=11, fontweight='500', color='white')
ax.set_ylabel('Signal Intensity', fontsize=12, fontweight='500', color='#94A3B8')

# Dark theme styling
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#334155')
ax.spines['bottom'].set_color('#334155')
ax.tick_params(colors='#94A3B8', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.2, color='#475569')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support