我有一个数组,比如:
[1,3,5,2,12,12,3,6,…]等,在代表蛾类的1-12之间变化。
现在,我可以用
plt.hist(months,range(1, 13))
plt.title("Job Request per month")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
现在,它显示直方图上唯一值的计数。然而,我找不到一个方法来与条形图。
完整代码:
from pymongo import MongoClient
import matplotlib.pyplot as plt
def main():
client = MongoClient('mongodb://a12345:a12345@127.0.0.1:27017/')
db = client['newDatabase']
collection = db['jobs']
cursor = collection.find({}, {'_constructed': 1})
months = []
for document in cursor:
if '_constructed' in document:
months.append(document['_constructed'].month)
print(months);
plt.bar(months, range(1, 13))
plt.title("Job Request per month")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()
if __name__ == "__main__":
main()
试试这个:
您可以使用
np.bincount
先计算months
,然后绘制:相关问题 更多 >
编程相关推荐