График не обновляется из пользовательского ввода с помощью виджета кнопок в matplotlibPython

Программы на Python
Anonymous
График не обновляется из пользовательского ввода с помощью виджета кнопок в matplotlib

Сообщение Anonymous »


I have a matplotlib plot that I want to update based on user input. The user inputs three values for three parameters and based on these three inputs, a path gets constructed. The algorithm then takes every image in the directory of that path, overblends all images and displays them.

The algorithm normally works fine (without user input) but now, the plots never seem to update. The path gets constructed correctly based on the input, however. I checked that by printing the new path every time the update button is clicked.

Here is my code:
import matplotlib.pyplot as plt import ipywidgets as widgets from IPython.display import display import numpy as np # Function to update the plot based on button clicks def update_plot(param1, param2, param3): # Construct the path based on the selected values and the image filename based on slider positions path = f'C:/Users/Jeff/Desktop/images/{param1}mL VE-Wasser + {param2} L Stickstoff +{param3} W' new_path = path + '/*.JPG' # Create list to later save the individual segmented images segmented_imgs = [] for image in glob.glob(new_path): # Add all segmented images to a list of images (their numpy arrays) segmented_img = prepare_images() segmented_imgs.append(segmented_img) # Get the overblended final image overblended_img = sum(segmented_imgs) # Divide pixel intesities by number of images to get back to scale 0 to 1 overblended_img = overblended_img / len(segmented_imgs) # Plot spraying cone with different regions integrated over the image series (overblended) plt.figure(figsize=(10, 12)) plt.imshow(overblended_img) # Create interactive widgets for each parameter param1_widget = widgets.Text(value='', description='Medium in mL/min:') param2_widget = widgets.Text(value='', description='Gas in L/min:') param3_widget = widgets.Text(value='', description='Leistung in W:') # Create a button to update the plot update_button = widgets.Button(description="Update Plot") # Define the callback function for the button def on_button_clicked(b): update_plot(param1_widget.value, param2_widget.value, param3_widget.value) update_button.on_click(on_button_clicked) # Display the widgets and button display(param1_widget, param2_widget, param3_widget, update_button)

Источник: https://stackoverflow.com/questions/780 ... matplotlib

Вернуться в «Python»