Boa noite! Estou desenvolvendo uma tela no python usando flet. Porém só consigo plotar um grafico uma vez, quando altero os dados o gráfico não é atualizado na tela.
Aqui está o código:
import flet as ft
import CalcularParametros
import matplotlib
import matplotlib.pyplot as plt
from flet.matplotlib_chart import MatplotlibChart
matplotlib.use("svg")
def main(page: ft.Page):
    page.title = "Transient Response Parameters"
    #page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.window_width = 550
    page.window_height = 820
    page.window_maximizable = False
    page.window_resizable = False
    def pick_files_result(e: ft.FilePickerResultEvent):
        selected_files.value = (
           ", ".join(map(lambda f: f.path, e.files)) if e.files else "Nenhum arquivo selecionado!"
        )
        
        nome_arquivo.value = (
           ", ".join(map(lambda f: f.name, e.files)) if e.files else "Nenhum arquivo selecionado!"
        )
        
        page.update()
    pick_files_dialog = ft.FilePicker(on_result=pick_files_result)
    selected_files = ft.Text()
    nome_arquivo = ft.Text()
    
    page.overlay.append(pick_files_dialog)
    
    # Incluindo botão pesquisar
    botao_pesquisar = ft.ElevatedButton("Escolher Arquivo",icon=ft.icons.UPLOAD_FILE,on_click=lambda _: pick_files_dialog.pick_files(
                        allow_multiple=False,
                        allowed_extensions=["txt"]
                        ),
                        )
    
    def button_clicked(e):
        #tempo_amostragem.value = f"Tempo de amostragem: {label1.value}"
        #degrau.value = f"Degrau: {label2.value}"
        try:
            resposta_planta.value = CalcularParametros.calcular_parametros(label1.value, label2.value, selected_files.value)
        except:
            pass
            
        try:     
            arrays = CalcularParametros.obter_array(label1.value, selected_files.value)
            
            tempo = arrays[0]
            saida = arrays[1]
            
            fig, ax = plt.subplots()
            
            ax.plot(tempo, saida, linestyle='-', color='b')
            ax.set_ylabel("Saída")
            ax.set_xlabel("Tempo de Amostragem")
            ax.set_title("Resultados")
            ax.grid()
            
            grafico = ft.ResponsiveRow([MatplotlibChart(fig, expand=False, isolated=True, original_size=10)],alignment=ft.MainAxisAlignment.START)
            
            page.add(grafico)
            
        except:
            pass
        
        page.update()
        
    resposta_planta = ft.Text()
    #tempo_amostragem = ft.Text()
    label1 = ft.TextField(label="Tempo de Amostragem (segundos)", border_color='white', width=250, height=60, max_length=8)
    
    
    #degrau = ft.Text()
    label2 = ft.TextField(label="Valor do Degrau", border_color='white', width=250, height=60, max_length=8)
    
    botao_start = ft.ElevatedButton(text="Iniciar",on_click=button_clicked)
    
    
    page.add(
        
        ft.ResponsiveRow([label1, label2]),
    
        ft.ResponsiveRow([botao_pesquisar, botao_start], alignment=ft.MainAxisAlignment.START),
         
        ft.ResponsiveRow([resposta_planta]),
    )
ft.app(target=main)
 
            