代碼
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
# 資料集
x = [75, 70, 65, 60, 55, 50, 45, 40, 35, 30]
y = [22.44, 92.17, 31.74, 51.37, 20.92, 20.67, 20.32, 90.05, 19.84, 19.59]
r = np.corrcoef(x,y)[0][1]
print('相關系數r=',r)
# 繪制散點
plt.scatter(x,y,20,'red')
plt.show()
結果

畫出散點圖