Error Bar Chart

Organic vs Conventional Yields

Agricultural crop yield comparison between organic and conventional farming methods.

Output
Organic vs Conventional Yields
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Crop yield data
crops = ['Wheat', 'Corn', 'Rice', 'Soybean', 'Barley']
organic = np.array([3.2, 8.5, 4.8, 2.4, 2.9])
conventional = np.array([4.1, 10.2, 5.5, 2.9, 3.5])
organic_err = np.array([0.4, 0.8, 0.5, 0.3, 0.35])
conv_err = np.array([0.3, 0.6, 0.4, 0.25, 0.3])

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

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

bars1 = ax.bar(x - width/2, organic, width, yerr=organic_err, 
               label='Organic', color='#6CF527', edgecolor='#1f2937',
               capsize=5, error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
bars2 = ax.bar(x + width/2, conventional, width, yerr=conv_err,
               label='Conventional', color='#F5B027', edgecolor='#1f2937',
               capsize=5, error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

ax.set_xlabel('Crop Type', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Yield (tons/hectare)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Organic vs Conventional Farming Yields', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(crops)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(0, 13)
ax.grid(True, axis='y', 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