Error Bar Chart

Restaurant Customer Ratings

Customer satisfaction ratings comparison across restaurants with rating variability.

Output
Restaurant Customer Ratings
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# Restaurant rating data
categories = ['Food\nQuality', 'Service', 'Ambiance', 'Value', 'Cleanliness']
restaurant_a = np.array([4.5, 4.2, 4.8, 3.8, 4.6])
restaurant_b = np.array([4.2, 4.6, 4.0, 4.4, 4.5])
restaurant_c = np.array([4.7, 3.9, 4.3, 4.1, 4.4])
err = np.array([0.25, 0.3, 0.2, 0.35, 0.2])

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

x = np.arange(len(categories))
width = 0.25

ax.bar(x - width, restaurant_a, width, yerr=err, label='Chez Pierre',
       color='#F5276C', edgecolor='#1f2937', capsize=4,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, restaurant_b, width, yerr=err, label='The Golden Fork',
       color='#F5B027', edgecolor='#1f2937', capsize=4,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, restaurant_c, width, yerr=err, label='Sakura Garden',
       color='#27D3F5', edgecolor='#1f2937', capsize=4,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

ax.axhline(y=4.0, color='#6CF527', linestyle='--', linewidth=1.5, 
           label='Good Rating (4.0)', alpha=0.7)

ax.set_xlabel('Category', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Rating (out of 5)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Restaurant Comparison: Customer Ratings', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(categories)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=9, loc='lower right')
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(3.0, 5.2)
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