Matplotlib -> Scatter
1. Plot sederhana scatter plot menggunakan matplotlib
import matplotlib.pyplot as plt
x = [ 2, 4, 6, 8, 10, 11, 11.5, 11.7]
y = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 ] #bilang pecahan/ float pada x dan y
#plot scatter x dan y
plt.scatter(x, y, label='Data 1', color='r')
plt.xlabel('Sumbu X')
plt.ylabel('Sumbu Y')
plt.title('Contoh Scatter Plot')
plt.legend()
plt.show()
(Referensi : Indonesia Belajar = Youtube)
x1 = [ 2, 4, 6, 8, 10, 11, 11.5, 11.7]
y1 = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 ] #bilang pecahan/ float pada x dan y
x2 = [8, 8.5, 9, 9.5, 10, 10.5, 11]
y2 = [3, 3.5, 3.7, 4, 4.5, 5, 5.2]
#plot scatter x dan y
plt.scatter(x1, y1, label='Data 1', color='r')
plt.scatter(x2, y2, label='Data 2', color='b')
plt.xlabel('Sumbu X')
plt.ylabel('Sumbu Y')
plt.title('Multiple Scatter Plot')
plt.legend()
plt.show()
3. Pengaturan marker
x1 = [ 2, 4, 6, 8, 10, 11, 11.5, 11.7]
y1 = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 ] #bilang pecahan/ float pada x dan y
x2 = [8, 8.5, 9, 9.5, 10, 10.5, 11]
y2 = [3, 3.5, 3.7, 4, 4.5, 5, 5.2]
plt.scatter(x1, y1, color='cyan', linewidths=1, marker ='s', edgecolor='red', s=100)
plt.scatter(x2, y2, color='yellow', linewidths=1, marker ='^', edgecolor='blue', s=200)
#linewidths = garis tepi, makin besar nilai makin tebal
#marker = s berarti square bentuk nya
#edgecolor= warna garis tepi
#kalau mau perbesar markernya bisa diatur s nya
4. scatter plot untuk data multi dimensi
iris.keys()
#iris suatu df dari module sklearn, keys memanggil dictionari atau nama file nya
.T
#tranpose
Komentar
Posting Komentar