獲取 Matplotlib 直方圖函式中的 bin 資訊
要獲取 matplotlib 直方圖函式中的 bin 資訊,我們可以採取以下步驟 -
為資料 和 bin 建立一個數字列表。
使用直方圖()方法計算一組資料的直方圖。
從直方圖(第 2 步)獲取直方圖 和邊緣 。
找出直方圖中的頻率。
使用箱 (步驟 1) 和頻率 (步驟 4) 資料製作一個條形圖。
要顯示圖形,請使用show()方法。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True a = [-0.125, .15, 8.75, 72.5, -44.245, 88.45] bins = np.arange(-180, 181, 20) hist, edges = np.histogram(a, bins) freq = hist/float(hist.sum()) plt.bar(bins[:-1], freq, width=20, align="edge", ec="k", color='red') plt.show()
輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP