'Select pickle file to plot in Voila

I'm creating some plots in python and save them with pickle. Now I want to have a dropdown in Voila to select the file and to plot it. But I can't find a way to update the plot. Creating the dropdown with the files and observe the change is not the problem. This is my example code:

with open('plots/20211202.obj', 'rb') as file:
   fig = pickle.load(file)

def update():
   with open('plots/20211203.obj', 'rb') as file:
       fig = pickle.load(file)   
   fig.canvas.draw()
   fig.canvas.flush_events()

With this example it should just change the xxx2.obj file to xxx3.obj file but it doesn't change anything in the plot. What am I missing here?

Thanks and best regards!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source