# code2.1c.py # import plotsvg <-- not accessible import matplotlib import matplotlib.pyplot as plt import numpy as np import numpy.random as rnd import hwblines as hl import statpos as sp sigmafit = 0.3 #varaxis = True nline = 6 lines = np.arange(nline,dtype='f') # posx = np.arange(nline,dtype='f') # posy = np.arange(nline,dtype='f') ndata = 200 #--- Main program starts here. --- print('--- Read a file and make a cumulative plot ---') print("MatPlotLib Version." + str(matplotlib.__version__)) print("NumPy Version." + str(np.__version__)) # The following line in code2.1a.py is replaced # f = hf.fileRead('tab2.1x.csv', False); x = f.xa; etc. sig = 0.3 # fitting parameter x = rnd.normal(8.5, 1.5, ndata) x.sort() y = np.arange(ndata, dtype="f") for i in range(ndata): y[i] = i + 1 med = np.median(x) aver = np.average(x) sigma = np.std(x) for loop in range(2): varaxis = (loop==1) if varaxis: f2 = hl.binwidths.varbins(x, y, ndata, aver, sigma, sig, True) zz = f2.za dz = f2.dz f3 = hl.accumlines.prepareLine(x, zz, ndata, 0.0, False) else: f3 = hl.accumlines.prepareLine(x, y, ndata, 0.0, False) u = f3.ua v = f3.va plt.plot(u, v) if varaxis: fp = sp.positions.posn(lines,nline,x,zz,ndata,aver,sigma,med) else: fp = sp.positions.posn(lines,nline,x,y,ndata,aver,sigma,med) 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) font1 = {'family':'serif','color':'blue','size':11} font2 = {'family':'serif','color':'darkred','size':12} plt.title("Figs. P1 or 2.2 Cumulative distribution", fontdict = font1) plt.xlabel("Observed values", fontdict = font2) plt.ylabel("Cumulative distribution", fontdict = font2) # plt.ylabel("Cumulative percent", fontdict = font2) if not varaxis: plt.grid() plt.show()