Error Bar Chart

Plant Protein and Fiber Content

Protein and fiber content comparison of popular plant-based protein sources.

Output
Plant Protein and Fiber Content
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

proteins = ['Tofu', 'Tempeh', 'Seitan', 'Lentils', 'Chickpeas', 'Black Beans']
protein_g = np.array([8, 19, 25, 9, 7.5, 8.5])
fiber_g = np.array([0.5, 5, 1, 8, 6, 7.5])
protein_err = np.array([1, 2, 3, 1, 0.8, 1])
fiber_err = np.array([0.1, 0.5, 0.2, 1, 0.6, 0.8])

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

x = np.arange(len(proteins))
width = 0.35

ax.bar(x - width/2, protein_g, width, yerr=protein_err, label='Protein (g/100g)',
       color='#F5276C', edgecolor='white', linewidth=1.5, capsize=5,
       error_kw={'ecolor': '#374151', 'elinewidth': 2})
ax.bar(x + width/2, fiber_g, width, yerr=fiber_err, label='Fiber (g/100g)',
       color='#6CF527', edgecolor='white', linewidth=1.5, capsize=5,
       error_kw={'ecolor': '#374151', 'elinewidth': 2})

ax.set_xlabel('Food Source', fontsize=12, color='#374151', fontweight='600')
ax.set_ylabel('Content (g per 100g)', fontsize=12, color='#374151', fontweight='600')
ax.set_title('Plant Protein and Fiber Content', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks(x)
ax.set_xticklabels(proteins, fontsize=10, rotation=15, ha='right')
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', fontsize=11)
ax.tick_params(colors='#6b7280', labelsize=10)
ax.set_ylim(0, 32)
ax.grid(True, axis='y', alpha=0.4, color='#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#d1d5db')
ax.spines['bottom'].set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support