Bar Chart

Segmented Bar Chart

Segmented bars showing proportions

Output
Segmented Bar Chart
Python
import matplotlib.pyplot as plt
import numpy as np

categories = ['2020', '2021', '2022', '2023', '2024']
segments = {
    'Excellent': [15, 18, 22, 28, 32],
    'Good': [35, 38, 40, 42, 45],
    'Average': [30, 28, 25, 20, 16],
    'Poor': [20, 16, 13, 10, 7]
}
colors = ['#22c55e', '#6366f1', '#f59e0b', '#ef4444']

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

x = np.arange(len(categories))
width = 0.65
bottom = np.zeros(len(categories))

for (label, values), color in zip(segments.items(), colors):
    ax.bar(x, values, width, bottom=bottom, label=label, color=color, edgecolor='none')
    bottom += values

ax.set_xticks(x)
ax.set_xticklabels(categories, color='#374151', fontsize=10)
ax.set_ylabel('Percentage (%)', color='#6b7280', fontsize=11)
ax.set_ylim(0, 100)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#e5e7eb')
ax.spines['bottom'].set_color('#e5e7eb')
ax.tick_params(axis='both', colors='#6b7280', labelsize=9)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), ncol=4, frameon=False, labelcolor='#374151', fontsize=9)
ax.set_title('Customer Satisfaction Trend', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support