File size: 1,321 Bytes
d323f57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
import matplotlib.pyplot as plt

# ── Parameters ─────────────────────────────────────────────────────────────
seed    = 4900
color   = "coral"

# ── Data ────────────────────────────────────────────────────────────────────
labels  = ['A', 'B', 'C', 'D']
heights = [1.49, 1.40, 3.60, 1.51]

# ── Plot ────────────────────────────────────────────────────────────────────
fig, ax = plt.subplots(figsize=(7, 4))
bars = ax.bar(labels, heights, color=color, edgecolor='white', linewidth=0.5)
ax.axhline(0, color='black', linewidth=0.8)
for bar, h in zip(bars, heights):
    va = 'bottom' if h >= 0 else 'top'
    offset = 0.05 if h >= 0 else -0.05
    ax.text(bar.get_x() + bar.get_width()/2, h + offset,
            f'{h:.2f}', ha='center', va=va, fontsize=8, fontweight='bold')
ax.set_title("Bar Chart  (4 categories)")
ax.set_xlabel("Category")
ax.set_ylabel("Value")
fig.tight_layout()
plt.show()