Bar Chart
Profit Loss Bar
Positive/negative values with color coding.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'positive': '#10B981',
'negative': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
values = [15, -8, 22, -5, 18, 30]
colors = [COLORS['positive'] if v >= 0 else COLORS['negative'] for v in values]
x = np.arange(len(months))
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
for i, (v, c) in enumerate(zip(values, colors)):
ax.bar(i, v, width=0.5, color=c, alpha=0.15, zorder=1)
ax.bar(i, v, width=0.4, color=c, alpha=0.85, edgecolor='white', linewidth=2, zorder=3)
ax.axhline(0, color=COLORS['text'], linewidth=1, zorder=2)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_visible(False)
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=1, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xticks(x)
ax.set_xticklabels(months)
ax.set_ylabel('Profit/Loss ($K)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕