📦 Boxplot (Distribution with Quartiles & Outliers)

A boxplot displays the distribution of numerical data based on:

  • Quartiles (25%, 50%, 75%)
  • Interquartile Range (IQR)
  • Outliers (points outside 1.5 × IQR)
plt.figure(figsize=(12,6))
sns.boxplot(x='parental level of education', y='math score', data=df)

🏷️ Adding hue for Segmentation

plt.figure(figsize=(12,6))
sns.boxplot(x='parental level of education', y='math score', data=df, hue='gender')

📍 Moving Legend Outside

plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

🎨 Boxplot Styling

Orientation (Horizontal Boxplot)

Switch X and Y for readability:

sns.boxplot(x='math score', y='parental level of education', data=df, orient='h')

Width of Boxes

plt.figure(figsize=(12,6))
sns.boxplot(x='parental level of education', y='math score', data=df, hue='gender', width=0.3)

🎻 Violinplot (KDE + Boxplot Hybrid)

A violin plot visualizes the distribution using:

  • Kernel Density Estimation (KDE)
  • Boxplot elements (optional)
plt.figure(figsize=(12,6))
sns.violinplot(x='parental level of education', y='math score', data=df)

🏷️ Adding hue

plt.figure(figsize=(12,6))
sns.violinplot(x='parental level of education', y='math score', data=df, hue='gender')

🎭 Violinplot Parameters

Split Violins for Comparison

plt.figure(figsize=(12,6))
sns.violinplot(x='parental level of education', y='math score', data=df, hue='gender', split=True)

Different Inner Representations

sns.violinplot(x='parental level of education', y='math score', data=df, inner=None)        # No inner elements
sns.violinplot(x='parental level of education', y='math score', data=df, inner='box')       # Mini boxplot
sns.violinplot(x='parental level of education', y='math score', data=df, inner='quartile')  # Quartiles
sns.violinplot(x='parental level of education', y='math score', data=df, inner='stick')     # Individual datapoints

Orientation (Horizontal Violin)

sns.violinplot(x='math score', y='parental level of education', data=df)

Bandwidth Control (Smoothing)

plt.figure(figsize=(12,6))
sns.violinplot(x='parental level of education', y='math score', data=df, bw=0.1)

🐝 Swarmplot (Scatterplot for Categories)

A swarmplot shows individual data points without overlapping.

sns.swarmplot(x='math score', data=df)
sns.swarmplot(x='math score', data=df, size=2)

🏷️ Swarmplot with Categories

sns.swarmplot(x='math score', y='race/ethnicity', data=df, size=3)
sns.swarmplot(x='race/ethnicity', y='math score', data=df, size=3)

🏷️ Swarmplot with Hue

plt.figure(figsize=(12,6))
sns.swarmplot(x='race/ethnicity', y='math score', data=df, hue='gender')

🏷️ dodge=True for Gender Comparison

plt.figure(figsize=(12,6))
sns.swarmplot(x='race/ethnicity', y='math score', data=df, hue='gender', dodge=True)

📦 Boxenplot (Letter-Value Plot)

A boxenplot provides a detailed quantile-based summary of data distribution.

📜 Reference Paper: Letter-Value Plot

sns.boxenplot(x='math score', y='race/ethnicity', data=df)
sns.boxenplot(x='race/ethnicity', y='math score', data=df)

🏷️ Boxenplot with Hue

plt.figure(figsize=(12,6))
sns.boxenplot(x='race/ethnicity', y='math score', data=df, hue='gender')

🔗 References