Error Bar Chart

Podcast Listening by Generation

Podcast genre preferences comparison across different generations.

Output
Podcast Listening by Generation
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

genres = ['True Crime', 'Comedy', 'News', 'Education', 'Business', 'Health']
gen_z = np.array([45, 62, 28, 42, 25, 35])
millennials = np.array([52, 48, 42, 55, 58, 45])
gen_x = np.array([38, 35, 58, 48, 52, 42])
err = np.array([6, 7, 5, 6, 7, 5])

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

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

ax.bar(x - width, gen_z, width, yerr=err, label='Gen Z',
       color='#F5276C', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x, millennials, width, yerr=err, label='Millennials',
       color='#27D3F5', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
ax.bar(x + width, gen_x, width, yerr=err, label='Gen X',
       color='#6CF527', edgecolor='white', linewidth=1.5, capsize=3,
       error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

ax.set_xlabel('Genre', fontsize=12, color='#374151', fontweight='600')
ax.set_ylabel('Weekly Listeners (%)', fontsize=12, color='#374151', fontweight='600')
ax.set_title('Podcast Listening by Generation', fontsize=15, 
             color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks(x)
ax.set_xticklabels(genres, fontsize=11)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=10)
ax.set_ylim(0, 80)
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