# makeData.py -- simple Monte Carlo program to make input data for ML fit # for now writes output to monitor (need to capture in file) # G. Cowan, RHUL Physics, November 2019 import matplotlib import matplotlib.pyplot as plt import numpy as np # generate data and store in numpy array, put into histogram numVal = 10000 nBins = 100 rMin = 0. rMax = 1. xMin = 0.; xMax = 10.; xi = 1.; rData = np.random.uniform(rMin, rMax, numVal) xData = - xi * np.log(rData) for i in range(numVal) : print (xData[i]) xHist, bin_edges = np.histogram(xData, bins=nBins, range=(xMin, xMax)) # make plot and save in file binLo, binHi = bin_edges[:-1], bin_edges[1:] xPlot = np.array([binLo, binHi]).T.flatten() yPlot = np.array([xHist, xHist]).T.flatten() fig, ax = plt.subplots(1,1) plt.gcf().subplots_adjust(bottom=0.15) plt.gcf().subplots_adjust(left=0.15) ax.set_xlim((xMin, xMax)) ax.set_ylim((0., 1000)) plt.xlabel(r'$x$', labelpad=0) plt.plot(xPlot, yPlot) plt.show() plt.savefig("uniformHist.png", format='png')