Selasa, 27 September 2022

Bereksperimen dengan pylab

Menginstall pylab

bash$ python3 -m pip install matplotlib

Membuat grafik di pylab

import pylab
pylab.figure(1)
pylab.plot([1,2,3,4], [1,7,3,5])
pylab.show() 

-------------------------------------------

Menghitung bunga menggunakan pylab

import pylab
principal = 10000
interestRate = 0.1
years = 20
values = []
for i in range(years + 1):
    values.append(principal)
    principal += principal*interestRate
pylab.plot(values)
pylab.show()



--------------------------------------------------
Mengubah style di pylab

import pylab
principal = 10000
interestRate = 0.1
years = 20
values = []
for i in range(years + 1):
    values.append(principal)
    principal += principal*interestRate


pylab.title("5% Growth, Compounded Annually", fontsize = "xx-large")
pylab.xlabel('Years of Compounding')
pylab.ylabel('Value of Principal ($)')
pylab.plot(values, linewidth = 30)
pylab.plot(values)
pylab.show()


------------------------------------------




Tidak ada komentar:

Posting Komentar