MEMBUAT TAMPILAN GRAFIK DATA STATISTIK
MENGGUNAKAN BAHASA PEMROGRAMAN PYTHON
Oleh :
TEGUH IMAN ARDIANSYAH
1215031073
Perbandingan jumlah kendaraan pada tahun 2005 - 2011
Tampilan grafik
Syntax program:
import numpy as np
import matplotlib.pyplot as plt
N = 7
mobilpenumpangMeans = (5076230,6035291,6877229,7489852,7910407,8891041,9548866)
ind = np.arange(N)
width = 0.3
plt.subplot(111)
rects1 = plt.bar(ind, mobilpenumpangMeans, width, color='r')
sepedamotorMeans = (28531831,32528758,41955128,47683681,52767093,61078188,68839341)
rects2 = plt.bar(ind+width, sepedamotorMeans, width, color='g')
plt.ylabel('jumlah kendaraan')
plt.title('Perbandingan jumlah kendaraan pada tahun 2005 - 2011')
plt.xticks(ind+width, ('2005', '2006', '2007', '2008', '2009', '2010', '2011'))
plt.legend((rects1[0], rects2[0]), ('mobilpenumpang', 'sepedamotor'))
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x()+rect.get_width()-0.5 , 1*height, '%d'%int(height), ha='left', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
import matplotlib.pyplot as plt
N = 7
mobilpenumpangMeans = (5076230,6035291,6877229,7489852,7910407,8891041,9548866)
ind = np.arange(N)
width = 0.3
plt.subplot(111)
rects1 = plt.bar(ind, mobilpenumpangMeans, width, color='r')
sepedamotorMeans = (28531831,32528758,41955128,47683681,52767093,61078188,68839341)
rects2 = plt.bar(ind+width, sepedamotorMeans, width, color='g')
plt.ylabel('jumlah kendaraan')
plt.title('Perbandingan jumlah kendaraan pada tahun 2005 - 2011')
plt.xticks(ind+width, ('2005', '2006', '2007', '2008', '2009', '2010', '2011'))
plt.legend((rects1[0], rects2[0]), ('mobilpenumpang', 'sepedamotor'))
def autolabel(rects):
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x()+rect.get_width()-0.5 , 1*height, '%d'%int(height), ha='left', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()
Link sumber
http://www.bps.go.id/tab_sub/view.php?tabel=1&daftar=1&id_subyek=17¬ab=12
Tidak ada komentar:
Posting Komentar