2016-09-15 21 views
0

ヒストグラムがこのように見えるのはなぜですか?ビン内の高さが不均一なヒストグラム

import matplotlib.pyplot as plt 

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

dataは50万ソートされたポイントが含まれています。私は、次のコードを使用して、それをプロットしています。各ビンを上に滑らかにしてはいけませんか?

enter image description here

答えて

0

私はthis example from the matplotlib galleryを表示したいプロットの種類を考えます。したがって、histtype="stepfilled"またはhisttype="bar"のいずれかを使用する必要があります。

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() 

は、おそらく似た、あなたのデータに「フラット化」のいくつかの種類を使用する必要があります。

関連する問題