# Revising code2.1cc.py to code2.2ccc.py import matplotlib import matplotlib.pyplot as plt import numpy as np import numpy.random as rnd import hwblines2 as hl import statpos as sp #nline = 6 ndata = 200 #--- Main program starts here. --- print('--- Male a cumulative probability distribution ---') print("MatPlotLib Version." + str(matplotlib.__version__)) print("NumPy Version." + str(np.__version__)) yax = hl.tic_label(0.01) # yax.info() x = rnd.normal(8.5, 1.5, ndata) # x.sort() # redundant operation y = np.arange(ndata, dtype="f") z = np.arange(ndata, dtype="f") print() print('ndata=',ndata) for i in range(ndata): y[i] = (i + 0.5)/ndata # See Wikipedia, "Normal prob. plot" z[i] = yax.finvcumulat(y[i]) print(i+1,") ",f"{y[i]:,.3f}"," ",f"{z[i]:,.3f}") # end=" ") med = np.median(x); print('median = ',f"{med:,.3f}") aver = np.average(x); print('mean = ',f"{aver:,.3f}") sigma = np.std(x); print('sigma = ',f"{sigma:,.3f}") ax = plt.axes() ax.set_xlim(4.0, 13.0) ax.set_ylim(0.0, 1.0) ax.set_aspect(8./1.) xtic = np.arange(4, 14.0, 1.0) ax.set_xticks(xtic) ax.set_xlabel('Observed value') ax.set_yticks(yax.tics) ax.set_yticklabels(yax.labels) ax.set_ylabel('Probability') f3 = hl.zigzag(x, z, ndata) u = f3.ua v = f3.va plt.plot(u, v) # plt.plot(x,z,lw=0,ls='',marker='o',ms=3) #,mec='r',mew=2,mfc='r') ax.grid(True) font1 = {'family':'serif','color':'blue','size':11} font2 = {'family':'serif','color':'darkred','size':12} plt.title("Fig. P1, Cumulative distr.", fontdict = font1) #plt.xlabel("Observed values", fontdict = font2) #plt.ylabel("Cumulative distribution", fontdict = font2) # posx = fp.posx # posy = fp.posy # for i in range(nline): # print(i,'-th point =',f'{posx[i]:,.2f}, {posy[i]:,.2f}') # xs = np.array([posx[i]-1, posx[i]+1]) # ys = np.array([posy[i], posy[i]]) # plt.plot(xs, ys) plt.show()