Python 绘图问题:清除

时间:2021-04-27 09:48:57

标签: python matplotlib tkinter tkinter-canvas matplotlib-widget

我这几天一直遇到问题,

该程序允许您检索数据、创建数据并将其显示在图上。

我这样做是因为我们可以显示 2 条曲线或 3 条曲线,无论我们按什么按​​钮并快速显示。

因此,我的问题是要知道在当前状态下是否可以删除图表? 如果程序写得比较好?我还应该怎么做? 我的最后一个问题,我想创建一个函数,允许直接从图中检索数据,这可能吗?

self.fig = Figure(figsize=(6.25,4.16), dpi=96)
ax = self.fig.add_subplot(111)

def ref():
    is_cal = messagebox.askquestion("Mesure Référence","Le calibrage à t'il était fait ?")
    
    if is_cal == "yes":
        
        print("Cal = TRUE")
            
        FUNCTION GET DATA NO ISSUES WITH IT return X Y
           
        #Check if data is OK, matching number, not empty array
        if y.all():
            if x.all():
                
                ax.plot(x, y, label="Ref S21 Start {} Hz Pwr {}dBm Bw {} Stop {} Hz".format(self.startfreq, self.power ,self.rbw ,self.endfreq))
                #ax.set_title("DUT ??? : ??/??/????")
                ax.set_xscale("log")
                ax.set_xlabel("Fréquence (Hz)")
                ax.set_ylabel("Atténuation (dB)")
                ax.legend()
                ax.grid(True, which="both", ls="-")
                graph = FigureCanvasTkAgg(self.fig, master=canvas_display)
                graph.draw()
                graph.get_tk_widget().place(x=1,y=1)
                
                self.pdf = self.fig
                    
        else:
            print("Erreur")
            
        subsection_min['text'] = "  Atténuation minimum : {} dB".format(round(self.Minimum(y),1))
        subsection_max['text'] = "  Atténuation maximum : {} dB".format(round(self.Maximum(y),1))
        subsection_moy['text'] = "  Atténuation moyenne : {} dB".format(round(self.Average(y),1))
            
        self.averageref_value = self.Average(y)
                        
    if is_cal == "no":
        print("CAL = FALSE")
        messagebox.showerror("Mesure Référence", "Il est impossible de trouver la référence si le calibrage n'est pas correct / initialisé")



def dut():
    
    print("Print new graph")
    
    FUNCTION GET DATA NO ISSUES WITH IT return X Y
    
    self.x = x
    self.y = y

    is_ref = messagebox.askquestion("Mesure DUT", "La mesure de référence à t-elle était faite ?")
    
    if is_ref == "yes":
        
        #Check if data is OK, matching number, not empty array
        if y.all():
            if x.all():
                
                #Duplicate
                
                self.nbdut = self.nbdut + 1
                ax.plot(x, y, label="DUT {} S21 Start {} Hz Pwr {}dBm Bw {} Stop {} Hz".format(self.nbdut, self.startfreq, self.power ,self.rbw ,self.endfreq))
                ax.set_title("PLOT 1 : 22/04/2021")
                ax.set_xscale("log")
                ax.set_xlabel("Fréquence (Hz)")
                ax.set_ylabel("Atténuation (dB)")
                ax.legend()
                ax.grid(True, which="both", ls="-")
                graph = FigureCanvasTkAgg(self.fig, master=canvas_display)
                graph.draw()
                graph.get_tk_widget().place(x=1,y=1)
                
                self.pdf = self.fig
                
                
        else:
            print("Erreur")
        
        subsection_min['text'] = "  Atténuation minimum : {} dB".format(round(self.Minimum(y),1))
        subsection_max['text'] = "  Atténuation maximum : {} dB".format(round(self.Maximum(y),1))
        subsection_moy['text'] = "  Atténuation moyenne : {} dB".format(round(self.Average(y),1))
        
        self.averagedut_value = self.Average(y)

    if is_ref == "no":
        
        messagebox.showerror("Mesure DUT", "Lancez d'abord la mesure de référence avant la mesure DUT")
        
def raz():
    
    print("RAZ")
    #self.fig = Figure(figsize=(6.25,4.16), dpi=96)
    self.fig.ax().close()

0 个答案:

没有答案
相关问题