-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (34 loc) · 1.17 KB
/
Copy pathmain.py
File metadata and controls
41 lines (34 loc) · 1.17 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import matplotlib.pyplot as plt
import numpy as np
# Data untuk visualisasi
categories = ['Low Vision', 'Full Buta']
dunia = [124, 43.3] # Juta orang
indonesia = [6.4, 1.6] # Juta orang
# Pengaturan posisi batang
x = np.arange(len(categories))
width = 0.35 # Lebar batang
# Membuat bar chart
fig, ax = plt.subplots(figsize=(10, 6))
bars1 = ax.bar(x - width/2, dunia, width, label='Dunia', color='#66b3ff')
bars2 = ax.bar(x + width/2, indonesia, width, label='Indonesia', color='#ff9999')
# Menambahkan label dan judul
ax.set_xlabel('Kategori Gangguan Penglihatan')
ax.set_ylabel('Jumlah (Juta Orang)')
ax.set_title('Perbandingan Low Vision dan Full Buta di Dunia dan Indonesia')
ax.set_xticks(x)
ax.set_xticklabels(categories)
ax.legend()
# Menambahkan nilai di atas batang
def autolabel(bars):
for bar in bars:
height = bar.get_height()
ax.annotate(f'{height}',
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3), # Offset 3 poin ke atas
textcoords="offset points",
ha='center', va='bottom')
autolabel(bars1)
autolabel(bars2)
# Menampilkan plot
plt.tight_layout()
plt.show()