Faceted Scatter Plot
Immunization Response by Demographics
Immunological response patterns across demographics
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
np.random.seed(4444)
age_groups = ['18-30', '31-50', '51-65', '65+']
data = []
for age in age_groups:
n = 40
antibody_titer = np.random.uniform(100, 5000, n)
efficacy_slopes = {'18-30': 0.018, '31-50': 0.015, '51-65': 0.012, '65+': 0.008}
efficacy = efficacy_slopes[age] * np.log(antibody_titer) * 100 + np.random.normal(0, 5, n)
efficacy = np.clip(efficacy, 20, 99)
for a, e in zip(antibody_titer, efficacy):
data.append({'Antibody Titer': a, 'Protection (%)': e, 'Age Group': age})
df = pd.DataFrame(data)
df['Log Titer'] = np.log10(df['Antibody Titer'])
sns.set_style("whitegrid", {
'axes.facecolor': '#ffffff',
'figure.facecolor': '#ffffff',
'grid.color': '#eeeeee'
})
palette = ['#6CF527', '#27D3F5', '#F5B027', '#F5276C']
g = sns.lmplot(
data=df,
x='Log Titer',
y='Protection (%)',
hue='Age Group',
col='Age Group',
col_wrap=2,
height=3.5,
aspect=1.2,
palette=palette,
scatter_kws={'alpha': 0.7, 's': 52, 'edgecolor': 'white', 'linewidths': 0.6},
line_kws={'linewidth': 2.5},
ci=95
)
g.fig.set_facecolor('#ffffff')
for ax in g.axes.flat:
ax.set_facecolor('#ffffff')
for spine in ax.spines.values():
spine.set_color('#dddddd')
g.fig.suptitle('Age-Stratified Immune Response', fontsize=14, fontweight='bold', color='#1a1a1a', y=1.02)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Faceted Scatter Plot examples
☕