[英]Histogram with uneven heights within bins
我懷疑您的數據可能不是平面列表,而是列表列表或類似結構的列表。 在這種情況下, 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()
您可能必須在數據上使用某種類似的“扁平化”。
我認為matplotlib畫廊中的這個示例顯示了您想要的繪圖類型。 因此,您應該使用histtype="stepfilled"
或histtype="bar"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.