Bar Chart

Diverging Bars Light

Diverging bar chart with light styling

Output
Diverging Bars Light
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(123)

items = ['Item A', 'Item B', 'Item C', 'Item D', 'Item E', 'Item F', 'Item G', 'Item H']
values = np.array([-25, -15, -8, 5, 12, 22, 35, 45])

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

y_pos = np.arange(len(items))
colors = ['#ef4444' if v < 0 else '#22c55e' for v in values]

ax.barh(y_pos, values, height=0.65, color=colors, edgecolor='none')

for i, v in enumerate(values):
    offset = 2 if v >= 0 else -2
    ha = 'left' if v >= 0 else 'right'
    ax.text(v + offset, i, f'{v:+d}%', va='center', ha=ha, color='#374151', fontsize=9, fontweight='500')

ax.axvline(x=0, color='#9ca3af', linewidth=1)
ax.set_yticks(y_pos)
ax.set_yticklabels(items, color='#374151', fontsize=10)
ax.set_xlabel('Change (%)', color='#6b7280', fontsize=11)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#e5e7eb')
ax.tick_params(axis='x', colors='#6b7280', labelsize=9)
ax.tick_params(axis='y', length=0)
ax.xaxis.grid(True, color='#f3f4f6', linewidth=1)
ax.set_axisbelow(True)

ax.set_title('Year-over-Year Change', 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