【Python】直方圖繪製代碼

#繪製直方圖
def drawHist(heights):
    #創建直方圖
    #第一個參數爲待繪製的定量數據,不同於定性數據,這裏並沒有事先進行頻數統計
    #第二個參數爲劃分的區間個數
    bins = np.arange(0, 1.01, 0.01)
    n, bins, patches = pyplot.hist(heights, bins)
    pyplot.xlabel('x軸')
    pyplot.ylabel('y軸')
    pyplot.title('標題')
    pyplot.show()
    return n, bins, patches

a = np.array([1,2,3])
n, bins, patches = drawHist(a)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章