1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 ''' 5 因爲一系列不等的縱形圖組成,表示數據分佈的狀況 6 例如:某年級同窗的身高分佈 7 須要注意與 柱形圖的區別 8 ''' 9 10 # # 例 11 # mu = 100 #均值 12 # sigma = 20 # 標準差 13 # 14 # x = mu + sigma * np.random.random(1000) 15 # plt.hist(x,bins=20,density=True) 16 # plt.show() 17 # 18 # 19 # # 雙變量圖 頻率越低越暗 20 # # x的中心爲2 21 # x = np.random.randn(1000) +2 22 # # y的中心爲3 23 # y = np.random.randn(1000)+3 24 # 25 # plt.hist2d(x,y,bins=40) 26 # plt.show() 27 28 29 # 練習 30 ''' 31 隨機生成2000個數據,均值爲10, 方差3; 32 繪製兩個直方圖, bins =10 和50 ,normed /density 分別爲True,False; 33 隨機生成x,y 各2000個, x均值1 ,y 均值5; 34 繪製2-D直方圖, bins = 40; 35 ''' 36 # 均值 37 ava = 10 38 # 方差 39 variance = 3 40 41 sigma = np.sqrt(variance) 42 x = ava + sigma * np.random.random(2000) 43 44 plt.hist(x,bins=10,density=True) 45 plt.show() 46 47 plt.hist(x,bins=50,density=False) 48 plt.show() 49 50 x = np.random.randn(2000) +1 51 y = np.random.randn(2000) + 5 52 plt.hist2d(x,y,bins=40) 53 plt.show()
在將來面前,咱們永遠都是孩子。不斷思考,不斷學習,才能讓咱們走的更遠。dom
我的主頁:https://www.oceaneyes.cn/學習
我的學習博客:http://oceaneyes.top/spa
CSDN:https://blog.csdn.net/qq_16123129 .net
長按二維碼關注,一塊兒交流學習~~~code