为什么我的直方图看起来像这样?我使用下面的代码绘制它:箱内高度不均的直方图
import matplotlib.pyplot as plt
n, bins, patches = plt.hist(data, 25)
plt.show()
其中data
包含大约500,000排序点。顶部不应该平滑吗?
为什么我的直方图看起来像这样?我使用下面的代码绘制它:箱内高度不均的直方图
import matplotlib.pyplot as plt
n, bins, patches = plt.hist(data, 25)
plt.show()
其中data
包含大约500,000排序点。顶部不应该平滑吗?
我想this example from the matplotlib gallery显示你想要的那种情节。因此,您应该使用histtype="stepfilled"
或histtype="bar"
。
我怀疑你的数据可能不是一个扁平的列表,但是,例如,列表或类似结构的列表。在这种情况下,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()
你可能会使用某种对您的数据类似的“扁平化”。