def CreateFigures(self, params, fitOrSim): if fitOrSim == 'fit': graphLabel = 'Full complex fit: ' elif fitOrSim == 'sim': graphLabel = 'Simulated using: ' else: graphLabel = '' plt.close('all') # make layout for graphs gs0 = gridspec.GridSpec(1, 2) gs00 = gridspec.GridSpecFromSubplotSpec(4, 3, subplot_spec=gs0[0]) gs01 = gridspec.GridSpecFromSubplotSpec(4, 4, subplot_spec=gs0[1]) f = plt.figure(1, figsize=[8, 3.5], tight_layout='true') ########################################################### #### PLOT NYQUIST COMBINED FITTINGS #### ########################################################### nyGraph = plt.Subplot(f, gs01[:, :]) f.add_subplot(nyGraph) nyGraph.plot(self.activeData.zPrime, self.activeData.ZdoublePrime, 'bo', ls='--', markersize=2, linewidth=1, label='data: ' + self.activeData.dataNameNoExt) nyGraph.plot( self.funcreal(params), self.funcImg(params), 'ro', markersize=2, label= '\n%s\nLwire=%.5e\nRmem=%5.8f\nRcl=%5.8f\nQdl=%5.5f\nphi=%5.5f' % (graphLabel, params[0] * float(self.area.IE.get()), params[1] * float(self.area.IE.get()), params[2] * float(self.area.IE.get()), params[3], params[4])) plt.gca().invert_yaxis() plt.xticks(rotation=20) plt.xlabel('Re(Z)') plt.ylabel('Im(Z)') plt.legend(loc=2, fontsize=6) ########################################################### #### PLOT Phase vs w COMBINED FITTINGS #### ########################################################### phaseGraph = plt.Subplot(f, gs00[-4, :3]) f.add_subplot(phaseGraph) phaseGraph.plot(self.activeData.frequency, self.activeData.phase, 'bo', ls='--', markersize=2, linewidth=1) phaseGraph.plot(self.activeData.frequency, self.funcPhase(params), 'ro', markersize=2) plt.ylabel('phase') #plt.gca().set_yscale('log') plt.gca().invert_yaxis() plt.gca().set_xscale('log') ########################################################### #### PLOT |Z| vs w COMBINED FITTINGS #### ########################################################### modZgraph = plt.Subplot(f, gs00[-3, :3]) f.add_subplot(modZgraph) modZgraph.plot(self.activeData.frequency, self.activeData.modZExperimentalComplex, 'bo', ls='--', markersize=2, linewidth=1) modZgraph.plot(self.activeData.frequency, self.funcAbs(params), 'ro', markersize=2) plt.ylabel('|Z|') plt.gca().set_yscale('log') plt.gca().set_xscale('log') ########################################################### #### PLOT Im(Z) #### ########################################################### imZgraph = plt.Subplot(f, gs00[-2, :3]) f.add_subplot(imZgraph) imZgraph.plot(self.activeData.frequency, self.activeData.ZdoublePrime, 'bo', ls='--', markersize=2, linewidth=1) imZgraph.plot(self.activeData.frequency, (self.funcImg(params)), 'ro', markersize=2) plt.ylabel('Im(Z)') plt.gca().set_yscale('linear') plt.gca().set_xscale('log') plt.gca().set_xticks([]) ########################################################### #### PLOT Re(Z) #### ########################################################### reZgraph = plt.Subplot(f, gs00[-1, :3]) f.add_subplot(reZgraph) reZgraph.plot(self.activeData.frequency, self.activeData.zPrime, 'bo', ls='--', markersize=2, linewidth=1) reZgraph.plot(self.activeData.frequency, self.funcreal(params), 'ro', markersize=2) plt.xlabel('frequency') plt.ylabel('Re(Z)') plt.gca().set_yscale('log') plt.gca().set_xscale('log') ########################################################### #### Draw figure in Tkinter #### ########################################################### for widget in self.plotFrame.winfo_children(): widget.destroy() for widget in self.plotFrameToolBar.winfo_children(): widget.destroy() dataPlot = FigureCanvasTkAgg(f, master=self.plotFrame) dataPlot.close_event() dataPlot.draw() dataPlot.get_tk_widget().grid( row=0, sticky=N + S + E + W, ) toolbar = NavigationToolbar2Tk(dataPlot, self.plotFrameToolBar) toolbar.update() dataPlot._tkcanvas.grid(row=0, sticky=W + S) self.plotToSave = f print('done with plotting')
def show_entry_fields(): global dataset, dataset_test, labels, labels_test, labels_names, probCLF, features_names, labels_test, labels_test_result dataset,dataset_test,labels,labels_test,features_names = functions_RP.inicialize_data() try: dataset, dataset_test,labels_test,labels,features_names except NameError: label_classificar.configure(text="Não pode Classificar. Tem de fazer load de tudo!") else: dataset1 = dataset dataset_test1= dataset_test labels1= labels labels_test1= labels_test features_names1 = features_names if(var.get() == 0 or var3.get() == 0): print("Nao pode classificar") label_classificar.configure(text="Dados insuficientes para classificar! ") else: label_classificar.configure(text="") if(var4.get() == 1): dataset1, dataset_test1 = functions_RP.pre_processamento(dataset1, dataset_test1) if(var.get() != 0): labels1, labels_test1, labels_names1, probCLF = functions_RP.define_labels(var.get()) if(var1.get() != 0): features_names1, dataset1, dataset_test1 = functions_RP.features_selection(dataset1, dataset_test1, features_names1, labels1, var1.get(), 30, probCLF) if(var2.get() != 0): dataset1, dataset_test1 = functions_RP.features_reduction(dataset1, dataset_test1, labels1, var2.get(), 10) if(var3.get() == 1): labels_test_result = functions_RP.distMinClf_CV(dataset1, labels1, dataset_test1, labels_test1, probCLF, 'euclidean', labels_names) elif (var3.get() == 2): labels_test_result = functions_RP.distMinClf_CV(dataset1, labels1, dataset_test1, labels_test1, probCLF, 'mahalanobis', labels_names) elif(var3.get() == 3): labels_test_result = functions_RP.clfNaiveBayes(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) elif (var3.get() == 4): labels_test_result = functions_RP.clfSVM(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) elif(var3.get() == 5): labels_test_result = functions_RP.clfKNN(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) elif(var3.get() == 6): labels_test_result = functions_RP.clfRandomForest(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) elif (var3.get() == 7): labels_test_result = functions_RP.clfQDA(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) elif (var3.get() == 8): labels_test_result = functions_RP.clfLDA(dataset1, dataset_test1, labels1, labels_test1, labels_names, probCLF) if(probCLF == 'bin'): report, acc, matrix, rocScore = functions_RP.metricsClf(labels_test_result, labels_test1, labels_names, probCLF) label_report.configure(text=report) text_acc = "Accuracy: " + str(acc) label_aac.configure(text=text_acc) label_aac.grid_configure(row=7, column=2, columnspan=5) text_roc = "AUC: " + str(rocScore) label_roc_auc.configure(text=text_roc) text_matrix = "Matriz de Confusão: \n 0 1 \n0 "+ str(matrix[0,0]) + " " + str(matrix[0,1]) + "\n1 " + str(matrix[1,0]) + " " + str(matrix[1,1]) label_matrix.configure(text=text_matrix) label_matrix.grid_configure(row=9, column=2, columnspan=5, rowspan=4, sticky=N) frp, tpr, roc_auc = functions_RP.ROC(1, labels_test1, labels_test_result) f.set_visible(True) f.clear() f.add_axes canvas = FigureCanvasTkAgg(f) lw = 2 a = f.add_subplot(111) a.set_xlabel('True Positive Rate') a.set_ylabel('True Positive Rate') a.set_title('Receiver operating characteristic') a.axis((0.0,1.0,0.0,1.0)) a.plot(frp, tpr, color='darkorange',lw=lw, label='ROC curve (area = %0.2f)' % roc_auc) canvas.get_tk_widget().grid(row=17, column=2, rowspan=10, columnspan=6, padx=50, sticky=W, pady=20) else: report, acc, matrix = functions_RP.metricsClf(labels_test_result, labels_test1, labels_names, probCLF) f.clear() f.set_visible(False) canvas = FigureCanvasTkAgg(f) canvas.get_tk_widget().grid(row=17, column=2, rowspan=10, columnspan=6, padx=50, sticky=W, pady=20) canvas.close_event() report, acc, matrix = functions_RP.metricsClf(labels_test_result, labels_test1, labels_names, probCLF) label_report.configure(text=report) label_report.grid_configure(row=1, column=2, rowspan=9, columnspan=5, sticky=N) text_acc = "Accuracy: " + str(acc) label_aac.configure(text=text_acc) label_roc_auc.configure(text="") label_aac.grid_configure(row=10, column=2, columnspan = 5, sticky=N) text_matrix = "Matriz de Confusão: \n 1 2 3 4 5 6" for i in range(1,7): text_matrix = text_matrix + "\n" + str(i) + " " for j in range(0,6): text_matrix= text_matrix + str(matrix[i-1,j]) + " " print(text_matrix) label_matrix.configure(text=text_matrix) label_matrix.grid_configure(row=11, column=2, columnspan = 6, rowspan=8, sticky=N)