dof = 2*self.beta-1 return 1./np.sqrt(dof)*np.random.standard_t(dof, n) if __name__ == '__main__': if 0: ntest = 100 pvals_calib = np.zeros(ntest) pvals_direct = np.zeros(ntest) for i in range(ntest): data = np.random.randn(100) pvals_calib[i] = calibrated_dip_test(data) xF, yF = cum_distr(data) dip = dip_from_cdf(xF, yF) pvals_direct[i] = dip_pval_tabinterpol(dip, len(data)) from beeswarm import beeswarm beeswarm([pvals_calib, pvals_direct]) # should be uniform distribution between 0 and 1 plt.show() if 1: import time np.random.seed(1) data = np.random.randn(100) np.random.seed() t0 = time.time() pval = calibrated_dip_test(data) t1 = time.time() print("pval = {}".format(pval)) print("Time consumption calibrated dip test: {}".format(t1-t0))
fig, ax = plt.subplots() for dp in dps: query = """ SELECT Test_Item,Wafer_ID,Device,Unit,Measure FROM ACDC_RESULT INNER JOIN TEST_FLOW ON ACDC_RESULT.ID = TEST_FLOW.ID WHERE Desc='一致性' AND Test_Item =? AND Wafer_id=? AND DPS=?""" dd = curs.execute(query, (tn, wd, dp)) ff = dd.fetchall() # columns = ['测试项','wafer_id','芯片编号','单位','数据'] # data = pd.DataFrame(ff,columns = columns) fdata = [i[4] for i in ff] frame.append(fdata) xticks.append("{}".format(dp)) colors.extend(GetColor(fdata)) Unit = ff[0][3] bsw.beeswarm(frame, ax=ax, col=colors) box = ax.boxplot( frame, positions=[0, 1, 2], whis=1.5, showfliers=False, medianprops=medianprops, meanprops=meanpointprops, meanline=False, showmeans=True, ) plt.xticks(np.arange(3), xticks) plt.xlabel("DPS (V)") plt.ylabel("{} ({})".format(tn, Unit)) # plt.xlim(-2,5) # plt.ylim(np.min(frame)-np.abs(np.max(frame)*0.1),np.max(frame)+np.abs(np.max(frame))*0.1)
def GetColor(x): colors = [] for item in x: if item > 0: colors.append("red") else: colors.append("blue") return colors d1 = np.random.uniform(low=-3, high=3, size=100) d2 = np.random.normal(size=100) print(d1) fig = plt.figure() fig.set_size_inches((8,8)) ax1 = plt.subplot(221) ax2 = plt.subplot(222) ax3 = plt.subplot(223) ax4 = plt.subplot(224) colors = GetColor(d1) + GetColor(d2) print(colors) beeswarm([d1,d2], method="swarm", labels=["Uniform","Normal"], col=colors, ax=ax3) beeswarm([d1,d2], method="swarm", labels=["Uniform","Normal"], col="black", ax=ax1) print(d1) beeswarm([d1,d2], method="swarm", labels=["Uniform","Normal"], col=["black","red"], ax=ax2) #beeswarm([d1,d2], method="swarm", labels=["Uniform","Normal"], col=["red","blue","orange"], ax=ax4) plt.tight_layout() plt.show()
if __name__ == '__main__': if 0: ntest = 100 pvals_calib = np.zeros(ntest) pvals_direct = np.zeros(ntest) for i in range(ntest): data = np.random.randn(100) pvals_calib[i] = calibrated_dip_test(data) xF, yF = cum_distr(data) dip = dip_from_cdf(xF, yF) pvals_direct[i] = dip_pval_tabinterpol(dip, len(data)) from beeswarm import beeswarm beeswarm([pvals_calib, pvals_direct ]) # should be uniform distribution between 0 and 1 plt.show() if 1: import time np.random.seed(1) data = np.random.randn(100) np.random.seed() t0 = time.time() pval = calibrated_dip_test(data) t1 = time.time() print("pval = {}".format(pval)) print("Time consumption calibrated dip test: {}".format(t1 - t0))
colors = [] q=np.percentile(x,[25,75]) w1 = q[1]+(q[1]-q[0])*1.5 w0 = q[0]-(q[1]-q[0])*1.5 x.sort() for item in x: if item > w1 or item < w0: colors.append("red") else: colors.append("blue") return colors # ## Create data np.random.seed(10) collectn_1 = np.random.normal(100, 30, 200) collectn_2 = np.random.normal(80, 30, 200) collectn_3 = np.random.normal(90, 20, 200) collectn_4 = np.random.normal(70, 25, 200) ## combine these different collections into a list #data_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4] data_to_plot = [collectn_1] # Create a figure instance fig = plt.figure(1, figsize=(9, 6)) # Create an axes instance ax = fig.add_subplot(111) colors = GetColor(collectn_1) # Create the boxplot bp = ax.boxplot(data_to_plot,positions = [0]) bsw.beeswarm(data_to_plot,ax=ax,col=colors)