Bar Chart

Temperature Range Bar

Range bars with min/max and average points.

Output
Temperature Range Bar
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'range': '#6366F1',
    'point': '#EF4444',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9',
}

categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
mins = [15, 18, 22, 28, 32, 35]
maxs = [25, 30, 35, 40, 45, 48]
avgs = [20, 24, 28, 34, 38, 42]

x = np.arange(len(categories))

fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# Range bars
for i, (mn, mx, avg) in enumerate(zip(mins, maxs, avgs)):
    ax.bar(i, mx - mn, bottom=mn, width=0.5, color=COLORS['range'], alpha=0.4,
           edgecolor='white', linewidth=1.5, zorder=2)
    # Average point
    ax.scatter(i, avg, s=80, color=COLORS['point'], edgecolors='white',
               linewidths=2, zorder=3)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])

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(categories)
ax.set_ylim(0, 55)
ax.set_ylabel('Temperature (°C)', fontsize=10, color=COLORS['text'], labelpad=10)

# Legend
ax.scatter([], [], s=80, color=COLORS['point'], edgecolors='white', linewidths=2, label='Average')
ax.bar([], [], color=COLORS['range'], alpha=0.4, label='Range (Min-Max)')
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
          ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support