import random import matplotlib import matplotlib.pyplot as plt size=1000 bucket=100 plt.figure() matplotlib.rcParams.update({‘font.size‘: 7}) plt.subplot(621) plt.xlabel("random.random") res = [random.random() for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(622) plt.xlabel("random.uniform") a=1 b=size res= [random.uniform(a,b) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(623) plt.xlabel("random.triangular") low=1 high = size res = [random.triangular(low,high) for _A in xrange(1, size)] plt.hist(res,bucket) plt.subplot(624) plt.xlabel("random.betavariate") alpha =1 beta =10 res=[random.betavariate(alpha,beta) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(625) plt.xlabel("random.expovariate") lambd = 1.0/((size+1)/2) res=[random.expovariate(lambd) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(626) plt.xlabel("random.gammavariate") alpha=1 beta=10 res=[random.gammavariate(alpha,beta) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(627) plt.xlabel("random.lognorvariate") mu=1 sigma=0.5 res=[random.lognormvariate(mu,sigma) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(628) plt.xlabel("random.normalvariate") mu=1 sigma=0.5 res=[random.normalvariate(mu,sigma) for _a in xrange(1,size)] plt.hist(res,bucket) plt.subplot(629) plt.xlabel("random.paretovariate") alpha=1 res=[random.paretovariate(alpha) for _a in xrange(1,size)] plt.hist(res,bucket) plt.tight_layout() plt.show()
时间: 2024-11-05 23:27:20