# code2.1b.py # import plotsvg <-- not accessible import matplotlib import matplotlib.pyplot as plt import scipy.stats as sp import numpy as np import hwbfiles as hf import hwblines as hl import statpos as sp #varaxis = True varaxis = False nline = 6 lines = np.arange(nline,dtype='f') posx = np.arange(nline,dtype='f') posy = np.arange(nline,dtype='f') #--- 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__)) tocheck = False f = hf.fileRead('tab2.1x.csv', False) ndata = f.ndata x = f.xa y = f.ya z = f.za print(ndata, ' points in ' + f.fname) med = np.median(x) aver = np.average(x) sigma = np.std(x) if varaxis: f2 = hl.binwidths.varbins(x, y, ndata, aver, sigma, 0.3, True) zz = f2.za #dz = f3.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()