2016-09-15 98 views
0

爲什麼我的直方圖看起來像這樣?我使用下面的代碼繪製它:箱內高度不均的直方圖

import matplotlib.pyplot as plt 

n, bins, patches = plt.hist(data, 25) 
plt.show() 

其中data包含大約500,000排序點。頂部不應該平滑嗎?

enter image description here

回答

1

我懷疑你的數據可能不是一個扁平的列表,但是,例如,列表或類似結構的列表。在這種情況下,hist將按子列表進行分類。該腳本演示的區別:

import random 
from matplotlib import pyplot as plt 

data = [[random.randint(0, x) for x in range(20)] for y in range(100)] 

plt.subplot(211) 
# structured 
plt.hist(data, 25) 

plt.subplot(212) 
# flattened 
plt.hist([i for l in data for i in l], 25) 

plt.show() 

你可能會使用某種對您的數據類似的「扁平化」。