Violin Plot
Gradient Violin Plot
Violin plot with gradient color progression
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import PolyCollection
# Data
np.random.seed(42)
data = [np.random.normal(loc, 1, 300) for loc in [4, 5, 6, 5.5, 7]]
labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
# Create figure
fig, ax = plt.subplots(figsize=(10, 6), facecolor='white')
# Violin plot
vp = ax.violinplot(data, positions=range(len(data)), widths=0.75,
showmeans=False, showmedians=True, showextrema=False)
# Gradient colors from teal to purple
gradient_colors = ['#14B8A6', '#22D3EE', '#6366F1', '#8B5CF6', '#D946EF']
for i, body in enumerate(vp['bodies']):
body.set_facecolor(gradient_colors[i])
body.set_edgecolor('white')
body.set_linewidth(2)
body.set_alpha(0.85)
vp['cmedians'].set_color('white')
vp['cmedians'].set_linewidth(2.5)
# Add mean dots
means = [np.mean(d) for d in data]
ax.scatter(range(len(data)), means, c='white', s=60, zorder=5,
edgecolor='#1F2937', linewidth=1.5)
# Customize axes
ax.set_xticks(range(len(data)))
ax.set_xticklabels(labels, fontsize=11, fontweight='500')
ax.set_ylabel('Daily Revenue ($K)', fontsize=12, fontweight='500', color='#374151')
# Clean styling
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#E5E7EB')
ax.spines['bottom'].set_color('#E5E7EB')
ax.tick_params(colors='#6B7280', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.3, color='#9CA3AF')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Violin Plot examples
☕