在这段代码中,我生成了随机数,然后对这些随机数取一个概率,最后用直方图来完成。但现在我想在mapreduce中运行这段代码。如何创建mapper.py和reducer.py?
# !/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from collections import Counter
def my_funct():
#Random Number Generating
x = np.random.randint(low=1, high=100, size=100000)
#np.random.seed(1223) # fixing the seed
counts = Counter(x)
total = sum(counts.values())
d1 = {k:v/total for k,v in counts.items()}
grad = d1.keys()
prob = d1.values()
print(str(grad))
print(str(prob))
#bins = 20
plt.hist(prob,bins=20, normed=1, facecolor='blue', alpha=0.5)
#plt.plot(bins, hist, 'r--')
plt.xlabel('Probability')
plt.ylabel('Number Of Students')
plt.title('Histogram of Students Grade')
plt.subplots_adjust(left=0.15)
plt.show()
# calling the function twice
my_funct()
# my_funct()
1条答案
按热度按时间h79rfbju1#
不能在mapreduce中使用matplotlib。它没有gui来显示结果