Error Bar Chart

Protein Intake Study Results

Nutrition study comparing high vs normal protein intake effects on lean body mass.

Output
Protein Intake Study Results
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Nutrition study data
time_points = ['Week 0', 'Week 4', 'Week 8', 'Week 12', 'Week 16']
high_protein = np.array([72, 74, 75.5, 76.8, 77.5])
normal_protein = np.array([72, 72.5, 73, 73.2, 73.5])
high_err = np.array([1.5, 1.2, 1.0, 0.9, 0.8])
normal_err = np.array([1.5, 1.4, 1.3, 1.2, 1.1])

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

x = np.arange(len(time_points))

ax.errorbar(x, high_protein, yerr=high_err, fmt='o-', color='#F5276C',
            ecolor='#F5276C', elinewidth=2, capsize=5, markersize=10,
            markeredgecolor='#1f2937', linewidth=2.5, label='High Protein (2g/kg)', alpha=0.9)
ax.fill_between(x, high_protein - high_err, high_protein + high_err, 
                color='#F5276C', alpha=0.15)

ax.errorbar(x, normal_protein, yerr=normal_err, fmt='s-', color='#27D3F5',
            ecolor='#27D3F5', elinewidth=2, capsize=5, markersize=9,
            markeredgecolor='#1f2937', linewidth=2.5, label='Normal Protein (0.8g/kg)', alpha=0.9)
ax.fill_between(x, normal_protein - normal_err, normal_protein + normal_err, 
                color='#27D3F5', alpha=0.15)

ax.set_xlabel('Study Period', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Lean Body Mass (kg)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Protein Intake Effect on Lean Body Mass', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(time_points)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(68, 82)
ax.grid(True, alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support