Bar Chart
Stacked Percentage Bars
Horizontal stacked bars showing composition
Output
Python
import matplotlib.pyplot as plt
import numpy as np
categories = ['Mobile', 'Desktop', 'Tablet', 'Smart TV', 'Wearable']
organic = [35, 42, 28, 45, 38]
paid = [25, 28, 32, 22, 28]
referral = [20, 15, 22, 18, 20]
direct = [20, 15, 18, 15, 14]
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
y_pos = np.arange(len(categories))
ax.barh(y_pos, organic, height=0.6, label='Organic', color='#6CF527')
ax.barh(y_pos, paid, height=0.6, left=organic, label='Paid', color='#27D3F5')
ax.barh(y_pos, referral, height=0.6, left=np.array(organic)+np.array(paid), label='Referral', color='#F5B027')
ax.barh(y_pos, direct, height=0.6, left=np.array(organic)+np.array(paid)+np.array(referral), label='Direct', color='#F5276C')
ax.set_yticks(y_pos)
ax.set_yticklabels(categories, color='white', fontsize=10)
ax.set_xlabel('Traffic Share (%)', color='#888888', fontsize=11)
ax.set_xlim(0, 100)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.tick_params(axis='both', colors='#888888', labelsize=9)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1), ncol=4, frameon=False, labelcolor='white', fontsize=9)
ax.set_title('Traffic Source by Device', color='white', fontsize=14, fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕