1、示例代碼
import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = 'SimHei' plt.rcParams['axes.unicode_minus'] = False # 生成標准正態分布的隨機數 1000 個 x = np.random.randn(900) # 生成與 x 不相關的變量 y1 y1 = np.random.randn(len(x)) # 生成與 x 強相關的變量 y1 y2 = x**3 + 2 # 在第 1 張圖中繪制兩個不相關的變量的藍色散點圖 plt.subplot(121) plt.plot(x, y1, '.', c ='b', label='不相關') plt.legend() # 在第 2 張圖中繪制兩個相關的變量的紅色星號散點圖, plt.subplot(122) plt.plot(x, y2, '*', c='green', label='強相關') plt.legend() plt.show()
2、圖形
。。。